OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <XCTest/XCTest.h> | 5 #import <XCTest/XCTest.h> |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
| 9 #include "components/url_formatter/url_formatter.h" |
9 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
10 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
11 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
12 #import "ios/web/public/test/http_server.h" | 13 #import "ios/web/public/test/http_server.h" |
13 #import "ios/web/public/test/http_server_util.h" | 14 #import "ios/web/public/test/http_server_util.h" |
14 | 15 |
15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
17 #endif | 18 #endif |
18 | 19 |
| 20 namespace { |
| 21 // Formats |url| for display and returns an NSString representation. |
| 22 NSString* GetFormattedURLString(const GURL& url) { |
| 23 return base::SysUTF16ToNSString(url_formatter::FormatUrl(url)); |
| 24 } |
| 25 } |
| 26 |
19 // Tests for tab history popup. | 27 // Tests for tab history popup. |
20 @interface TabHistoryPopupControllerTestCase : ChromeTestCase | 28 @interface TabHistoryPopupControllerTestCase : ChromeTestCase |
21 @end | 29 @end |
22 | 30 |
23 @implementation TabHistoryPopupControllerTestCase | 31 @implementation TabHistoryPopupControllerTestCase |
24 | 32 |
25 // Test that the tab history back and forward menus contain the expected entries | 33 // Test that the tab history back and forward menus contain the expected entries |
26 // for a series of navigations, and that tapping entries performs the | 34 // for a series of navigations, and that tapping entries performs the |
27 // appropriate navigation. | 35 // appropriate navigation. |
28 - (void)testTabHistoryMenu { | 36 - (void)testTabHistoryMenu { |
29 const GURL URL1 = web::test::HttpServer::MakeUrl("http://page1"); | 37 const GURL URL1 = web::test::HttpServer::MakeUrl("http://page1"); |
30 const GURL URL2 = web::test::HttpServer::MakeUrl("http://page2"); | 38 const GURL URL2 = web::test::HttpServer::MakeUrl("http://page2"); |
31 const GURL URL3 = web::test::HttpServer::MakeUrl("http://page3"); | 39 const GURL URL3 = web::test::HttpServer::MakeUrl("http://page3"); |
32 const GURL URL4 = web::test::HttpServer::MakeUrl("http://page4"); | 40 const GURL URL4 = web::test::HttpServer::MakeUrl("http://page4"); |
33 NSString* entry0 = @"New Tab"; | 41 NSString* entry0 = @"New Tab"; |
34 NSString* entry1 = base::SysUTF8ToNSString(URL1.spec()); | 42 NSString* entry1 = GetFormattedURLString(URL1); |
35 NSString* entry2 = base::SysUTF8ToNSString(URL2.spec()); | 43 NSString* entry2 = GetFormattedURLString(URL2); |
36 NSString* entry3 = base::SysUTF8ToNSString(URL3.spec()); | 44 NSString* entry3 = GetFormattedURLString(URL3); |
37 NSString* entry4 = base::SysUTF8ToNSString(URL4.spec()); | 45 NSString* entry4 = GetFormattedURLString(URL4); |
38 | 46 |
39 // Create map of canned responses and set up the test HTML server. | 47 // Create map of canned responses and set up the test HTML server. |
40 std::map<GURL, std::string> responses; | 48 std::map<GURL, std::string> responses; |
41 responses[URL1] = "page1"; | 49 responses[URL1] = "page1"; |
42 responses[URL2] = "page2"; | 50 responses[URL2] = "page2"; |
43 responses[URL3] = "page3"; | 51 responses[URL3] = "page3"; |
44 responses[URL4] = "page4"; | 52 responses[URL4] = "page4"; |
45 web::test::SetUpSimpleHttpServer(responses); | 53 web::test::SetUpSimpleHttpServer(responses); |
46 | 54 |
47 // Load 4 pages. | 55 // Load 4 pages. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 assertWithMatcher:grey_notNil()]; | 96 assertWithMatcher:grey_notNil()]; |
89 // Tap entry to go forward 2 pages, and verify that entry 3 is loaded. | 97 // Tap entry to go forward 2 pages, and verify that entry 3 is loaded. |
90 [[EarlGrey selectElementWithMatcher:grey_text(entry3)] | 98 [[EarlGrey selectElementWithMatcher:grey_text(entry3)] |
91 performAction:grey_tap()]; | 99 performAction:grey_tap()]; |
92 [[EarlGrey | 100 [[EarlGrey |
93 selectElementWithMatcher:chrome_test_util::OmniboxText(URL3.GetContent())] | 101 selectElementWithMatcher:chrome_test_util::OmniboxText(URL3.GetContent())] |
94 assertWithMatcher:grey_notNil()]; | 102 assertWithMatcher:grey_notNil()]; |
95 } | 103 } |
96 | 104 |
97 @end | 105 @end |
OLD | NEW |