1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef IOS_WEB_NAVIGATION_CRW_TEST_BACK_FORWARD_LIST_H_
6 #define IOS_WEB_NAVIGATION_CRW_TEST_BACK_FORWARD_LIST_H_
7 
8 #import <Foundation/Foundation.h>
9 
10 NS_ASSUME_NONNULL_BEGIN
11 
12 @class WKBackForwardListItem;
13 
14 // A CRWFakeBackForwardList can be used to stub out WKBackForwardList in tests.
15 @interface CRWFakeBackForwardList : NSObject
16 
17 // Returns an OCMock of WKBackForwardListItem with the given URL.
18 + (WKBackForwardListItem*)itemWithURLString:(NSString*)URL;
19 
20 // WKBackForwardList interface
21 @property(nullable, nonatomic, copy) NSArray<WKBackForwardListItem*>* backList;
22 @property(nullable, nonatomic, copy)
23     NSArray<WKBackForwardListItem*>* forwardList;
24 @property(nullable, nonatomic, strong) WKBackForwardListItem* currentItem;
25 @property(nullable, nonatomic, readonly, strong)
26     WKBackForwardListItem* backItem;
27 @property(nullable, nonatomic, readonly, strong)
28     WKBackForwardListItem* forwardItem;
29 - (nullable WKBackForwardListItem*)itemAtIndex:(NSInteger)index;
30 
31 // Resets this instance to simulate a session with no back/forward history, and
32 // a single entry for |currentItemURL| if it is not nil. If |currentItemURL| is
33 // nil, the session is reset to empty.
34 - (void)setCurrentURL:(nullable NSString*)currentItemURL;
35 
36 // Resets this instance to simulate a session with the current entry at
37 // |currentItemURL|, and back and forward history entries as specified in
38 // |backListURLs| and |forwardListURLs|.
39 - (void)setCurrentURL:(NSString*)currentItemURL
40          backListURLs:(nullable NSArray<NSString*>*)backListURLs
41       forwardListURLs:(nullable NSArray<NSString*>*)forwardListURLs;
42 
43 // Simulates go-to-index operation on this instance. Shuffles the items in this
44 // instance such that currentItem is at position |index| of the logical list
45 // formed by backList + currentItem + forwardList. backList[0] has index 0.
46 // |index| must be in the range [0, # of items in this instance).
47 - (void)moveCurrentToIndex:(NSUInteger)index;
48 
49 @end
50 
51 NS_ASSUME_NONNULL_END
52 
53 #endif  // IOS_WEB_NAVIGATION_CRW_TEST_BACK_FORWARD_LIST_H_
54