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