| 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 <EarlGrey/EarlGrey.h> |    5 #import <EarlGrey/EarlGrey.h> | 
|    6 #import <UIKit/UIKit.h> |    6 #import <UIKit/UIKit.h> | 
|    7 #import <XCTest/XCTest.h> |    7 #import <XCTest/XCTest.h> | 
|    8  |    8  | 
|    9 #include "base/ios/ios_util.h" |    9 #include "base/ios/ios_util.h" | 
|   10 #include "base/mac/bind_objc_block.h" |   10 #include "base/mac/bind_objc_block.h" | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   70     NSError* error = nil; |   70     NSError* error = nil; | 
|   71     [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |   71     [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 
|   72                                             expectedURL.GetContent())] |   72                                             expectedURL.GetContent())] | 
|   73         assertWithMatcher:grey_notNil() |   73         assertWithMatcher:grey_notNil() | 
|   74                     error:&error]; |   74                     error:&error]; | 
|   75     return (error == nil); |   75     return (error == nil); | 
|   76   }; |   76   }; | 
|   77   GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description); |   77   GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description); | 
|   78 } |   78 } | 
|   79  |   79  | 
|   80 // Asserts that the current web view containers contains |text|. |  | 
|   81 void AssertStringIsPresentOnPage(const std::string& text) { |  | 
|   82   id<GREYMatcher> response_matcher = |  | 
|   83       chrome_test_util::WebViewContainingText(text); |  | 
|   84   [[EarlGrey selectElementWithMatcher:response_matcher] |  | 
|   85       assertWithMatcher:grey_notNil()]; |  | 
|   86 } |  | 
|   87  |  | 
|   88 }  // namespace |   80 }  // namespace | 
|   89  |   81  | 
|   90 #pragma mark - Tests |   82 #pragma mark - Tests | 
|   91  |   83  | 
|   92 // Fullscreens tests for Chrome. |   84 // Fullscreens tests for Chrome. | 
|   93 @interface FullscreenTestCase : ChromeTestCase |   85 @interface FullscreenTestCase : ChromeTestCase | 
|   94  |   86  | 
|   95 @end |   87 @end | 
|   96  |   88  | 
|   97 @implementation FullscreenTestCase |   89 @implementation FullscreenTestCase | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  163   // Test that the toolbar is hidden after a user swipes up. |  155   // Test that the toolbar is hidden after a user swipes up. | 
|  164   HideToolbarUsingUI(); |  156   HideToolbarUsingUI(); | 
|  165   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  157   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  166 } |  158 } | 
|  167  |  159  | 
|  168 // Tests that link clicks from a chrome:// to chrome:// link result in the |  160 // Tests that link clicks from a chrome:// to chrome:// link result in the | 
|  169 // header being shown even if was not previously shown. |  161 // header being shown even if was not previously shown. | 
|  170 - (void)testChromeToChromeURLKeepsHeaderOnScreen { |  162 - (void)testChromeToChromeURLKeepsHeaderOnScreen { | 
|  171   const GURL kChromeAboutURL("chrome://chrome-urls"); |  163   const GURL kChromeAboutURL("chrome://chrome-urls"); | 
|  172   [ChromeEarlGrey loadURL:kChromeAboutURL]; |  164   [ChromeEarlGrey loadURL:kChromeAboutURL]; | 
|  173  |  165   [ChromeEarlGrey waitForWebViewContainingText:"chrome://version"]; | 
|  174   AssertStringIsPresentOnPage("chrome://version"); |  | 
|  175  |  166  | 
|  176   // Hide the toolbar. The page is not long enough to dismiss the toolbar using |  167   // Hide the toolbar. The page is not long enough to dismiss the toolbar using | 
|  177   // the UI so we have to zoom in. |  168   // the UI so we have to zoom in. | 
|  178   const char script[] = |  169   const char script[] = | 
|  179       "(function(){" |  170       "(function(){" | 
|  180       "var metas = document.getElementsByTagName('meta');" |  171       "var metas = document.getElementsByTagName('meta');" | 
|  181       "for (var i=0; i<metas.length; i++) {" |  172       "for (var i=0; i<metas.length; i++) {" | 
|  182       "  if (metas[i].getAttribute('name') == 'viewport') {" |  173       "  if (metas[i].getAttribute('name') == 'viewport') {" | 
|  183       "    metas[i].setAttribute('content', 'width=10');" |  174       "    metas[i].setAttribute('content', 'width=10');" | 
|  184       "    return;" |  175       "    return;" | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  243   std::map<GURL, std::string> responses; |  234   std::map<GURL, std::string> responses; | 
|  244   const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |  235   const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 
|  245   // This is a tall page -- necessary to make sure scrolling can hide away the |  236   // This is a tall page -- necessary to make sure scrolling can hide away the | 
|  246   // toolbar safely-- and with a link to reload itself. |  237   // toolbar safely-- and with a link to reload itself. | 
|  247   responses[URL] = |  238   responses[URL] = | 
|  248       "<p style='height:200em'>Tall page</p>" |  239       "<p style='height:200em'>Tall page</p>" | 
|  249       "<a onclick='window.location.reload();' id='link'>link</a>"; |  240       "<a onclick='window.location.reload();' id='link'>link</a>"; | 
|  250   web::test::SetUpSimpleHttpServer(responses); |  241   web::test::SetUpSimpleHttpServer(responses); | 
|  251  |  242  | 
|  252   [ChromeEarlGrey loadURL:URL]; |  243   [ChromeEarlGrey loadURL:URL]; | 
|  253   AssertStringIsPresentOnPage("Tall page"); |  244   [ChromeEarlGrey waitForWebViewContainingText:"Tall page"]; | 
|  254  |  245  | 
|  255   // Hide the toolbar. |  246   // Hide the toolbar. | 
|  256   HideToolbarUsingUI(); |  247   HideToolbarUsingUI(); | 
|  257   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  248   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  258  |  249  | 
|  259   chrome_test_util::TapWebViewElementWithId("link"); |  250   chrome_test_util::TapWebViewElementWithId("link"); | 
|  260  |  251  | 
|  261   // Main test is here: Make sure the header is still visible! |  252   // Main test is here: Make sure the header is still visible! | 
|  262   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  253   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
|  263 } |  254 } | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  283   javaScript = "window.close()"; |  274   javaScript = "window.close()"; | 
|  284   responses[destinationURL] = base::StringPrintf( |  275   responses[destinationURL] = base::StringPrintf( | 
|  285       "<p style='height:200em'>whatever</p><a onclick='%s' " |  276       "<p style='height:200em'>whatever</p><a onclick='%s' " | 
|  286       "id='link2'>link2</a>", |  277       "id='link2'>link2</a>", | 
|  287       javaScript.c_str()); |  278       javaScript.c_str()); | 
|  288  |  279  | 
|  289   web::test::SetUpSimpleHttpServer(responses); |  280   web::test::SetUpSimpleHttpServer(responses); | 
|  290   chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); |  281   chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); | 
|  291  |  282  | 
|  292   [ChromeEarlGrey loadURL:URL]; |  283   [ChromeEarlGrey loadURL:URL]; | 
|  293   AssertStringIsPresentOnPage("link1"); |  284   [ChromeEarlGrey waitForWebViewContainingText:"link1"]; | 
|  294   chrome_test_util::AssertMainTabCount(1); |  285   chrome_test_util::AssertMainTabCount(1); | 
|  295  |  286  | 
|  296   // Hide the toolbar. |  287   // Hide the toolbar. | 
|  297   HideToolbarUsingUI(); |  288   HideToolbarUsingUI(); | 
|  298   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  289   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  299  |  290  | 
|  300   // Open new window. |  291   // Open new window. | 
|  301   chrome_test_util::TapWebViewElementWithId("link1"); |  292   chrome_test_util::TapWebViewElementWithId("link1"); | 
|  302  |  293  | 
|  303   // Check that a new Tab was created. |  294   // Check that a new Tab was created. | 
|  304   AssertStringIsPresentOnPage("link2"); |  295   [ChromeEarlGrey waitForWebViewContainingText:"link2"]; | 
|  305   chrome_test_util::AssertMainTabCount(2); |  296   chrome_test_util::AssertMainTabCount(2); | 
|  306  |  297  | 
|  307   AssertURLIs(destinationURL); |  298   AssertURLIs(destinationURL); | 
|  308  |  299  | 
|  309   // Hide the toolbar. |  300   // Hide the toolbar. | 
|  310   HideToolbarUsingUI(); |  301   HideToolbarUsingUI(); | 
|  311   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  302   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  312  |  303  | 
|  313   // Close the tab. |  304   // Close the tab. | 
|  314   chrome_test_util::TapWebViewElementWithId("link2"); |  305   chrome_test_util::TapWebViewElementWithId("link2"); | 
|  315   AssertStringIsPresentOnPage("link1"); |  306   [ChromeEarlGrey waitForWebViewContainingText:"link1"]; | 
|  316  |  307  | 
|  317   // Make sure the toolbar is on the screen. |  308   // Make sure the toolbar is on the screen. | 
|  318   chrome_test_util::AssertMainTabCount(1); |  309   chrome_test_util::AssertMainTabCount(1); | 
|  319   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  310   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
|  320 } |  311 } | 
|  321  |  312  | 
|  322 // Tests that the header is shown when a regular page (non-native page) is |  313 // Tests that the header is shown when a regular page (non-native page) is | 
|  323 // loaded from a page where the header was not see before. |  314 // loaded from a page where the header was not see before. | 
|  324 // Also tests that auto-hide works correctly on new page loads. |  315 // Also tests that auto-hide works correctly on new page loads. | 
|  325 - (void)testShowHeaderOnRegularPageLoad { |  316 - (void)testShowHeaderOnRegularPageLoad { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  336                          "' id='link1'>link1</a>"; |  327                          "' id='link1'>link1</a>"; | 
|  337   // A long page representing many lines and a link to go back. |  328   // A long page representing many lines and a link to go back. | 
|  338   responses[destinationURL] = manyLines + |  329   responses[destinationURL] = manyLines + | 
|  339                               "<a href='javascript:void(0)' " |  330                               "<a href='javascript:void(0)' " | 
|  340                               "onclick='window.history.back()' " |  331                               "onclick='window.history.back()' " | 
|  341                               "id='link2'>link2</a>"; |  332                               "id='link2'>link2</a>"; | 
|  342   web::test::SetUpSimpleHttpServer(responses); |  333   web::test::SetUpSimpleHttpServer(responses); | 
|  343  |  334  | 
|  344   [ChromeEarlGrey loadURL:originURL]; |  335   [ChromeEarlGrey loadURL:originURL]; | 
|  345  |  336  | 
|  346   AssertStringIsPresentOnPage("link1"); |  337   [ChromeEarlGrey waitForWebViewContainingText:"link1"]; | 
|  347   // Dismiss the toolbar. |  338   // Dismiss the toolbar. | 
|  348   HideToolbarUsingUI(); |  339   HideToolbarUsingUI(); | 
|  349   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  340   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  350  |  341  | 
|  351   // Navigate to the other page. |  342   // Navigate to the other page. | 
|  352   chrome_test_util::TapWebViewElementWithId("link1"); |  343   chrome_test_util::TapWebViewElementWithId("link1"); | 
|  353   AssertStringIsPresentOnPage("link2"); |  344   [ChromeEarlGrey waitForWebViewContainingText:"link2"]; | 
|  354  |  345  | 
|  355   // Make sure toolbar is shown since a new load has started. |  346   // Make sure toolbar is shown since a new load has started. | 
|  356   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  347   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
|  357  |  348  | 
|  358   // Dismiss the toolbar. |  349   // Dismiss the toolbar. | 
|  359   HideToolbarUsingUI(); |  350   HideToolbarUsingUI(); | 
|  360   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  351   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  361  |  352  | 
|  362   // Go back. |  353   // Go back. | 
|  363   chrome_test_util::TapWebViewElementWithId("link2"); |  354   chrome_test_util::TapWebViewElementWithId("link2"); | 
|  364  |  355  | 
|  365   // Make sure the toolbar has loaded now that a new page has loaded. |  356   // Make sure the toolbar has loaded now that a new page has loaded. | 
|  366   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  357   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
|  367 } |  358 } | 
|  368  |  359  | 
|  369 // Tests that the header is shown when a native page is loaded from a page where |  360 // Tests that the header is shown when a native page is loaded from a page where | 
|  370 // the header was not seen before. |  361 // the header was not seen before. | 
|  371 - (void)testShowHeaderOnNativePageLoad { |  362 - (void)testShowHeaderOnNativePageLoad { | 
|  372   std::map<GURL, std::string> responses; |  363   std::map<GURL, std::string> responses; | 
|  373   const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |  364   const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 
|  374  |  365  | 
|  375   // A long page representing many lines and a link to go back. |  366   // A long page representing many lines and a link to go back. | 
|  376   std::string manyLines = |  367   std::string manyLines = | 
|  377       "<p style='height:100em'>a</p>" |  368       "<p style='height:100em'>a</p>" | 
|  378       "<a onclick='window.history.back()' id='link'>link</a>"; |  369       "<a onclick='window.history.back()' id='link'>link</a>"; | 
|  379   responses[URL] = manyLines; |  370   responses[URL] = manyLines; | 
|  380   web::test::SetUpSimpleHttpServer(responses); |  371   web::test::SetUpSimpleHttpServer(responses); | 
|  381  |  372  | 
|  382   [ChromeEarlGrey loadURL:URL]; |  373   [ChromeEarlGrey loadURL:URL]; | 
|  383   AssertStringIsPresentOnPage("link"); |  374   [ChromeEarlGrey waitForWebViewContainingText:"link"]; | 
|  384  |  375  | 
|  385   // Dismiss the toolbar. |  376   // Dismiss the toolbar. | 
|  386   HideToolbarUsingUI(); |  377   HideToolbarUsingUI(); | 
|  387   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  378   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  388  |  379  | 
|  389   // Go back to NTP, which is a native view. |  380   // Go back to NTP, which is a native view. | 
|  390   chrome_test_util::TapWebViewElementWithId("link"); |  381   chrome_test_util::TapWebViewElementWithId("link"); | 
|  391  |  382  | 
|  392   // Make sure the toolbar is visible now that a new page has loaded. |  383   // Make sure the toolbar is visible now that a new page has loaded. | 
|  393   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  384   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|  411   [ChromeEarlGrey loadURL:URL]; |  402   [ChromeEarlGrey loadURL:URL]; | 
|  412   HideToolbarUsingUI(); |  403   HideToolbarUsingUI(); | 
|  413   [ChromeEarlGreyUI waitForToolbarVisible:NO]; |  404   [ChromeEarlGreyUI waitForToolbarVisible:NO]; | 
|  414  |  405  | 
|  415   chrome_test_util::TapWebViewElementWithId("link"); |  406   chrome_test_util::TapWebViewElementWithId("link"); | 
|  416   AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); |  407   AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); | 
|  417   [ChromeEarlGreyUI waitForToolbarVisible:YES]; |  408   [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 
|  418 } |  409 } | 
|  419  |  410  | 
|  420 @end |  411 @end | 
| OLD | NEW |