| 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/strings/sys_string_conversions.h" |    9 #include "base/strings/sys_string_conversions.h" | 
|   10 #include "components/content_settings/core/browser/host_content_settings_map.h" |   10 #include "components/content_settings/core/browser/host_content_settings_map.h" | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   90   ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW); |   90   ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW); | 
|   91   web::test::SetUpFileBasedHttpServer(); |   91   web::test::SetUpFileBasedHttpServer(); | 
|   92  |   92  | 
|   93   const GURL testURL = GetTestUrl(); |   93   const GURL testURL = GetTestUrl(); | 
|   94   [ChromeEarlGrey loadURL:testURL]; |   94   [ChromeEarlGrey loadURL:testURL]; | 
|   95   chrome_test_util::AssertMainTabCount(1U); |   95   chrome_test_util::AssertMainTabCount(1U); | 
|   96  |   96  | 
|   97   // Tap on the test link and wait for the page to display "Click done", as an |   97   // Tap on the test link and wait for the page to display "Click done", as an | 
|   98   // indicator that the element was tapped. |   98   // indicator that the element was tapped. | 
|   99   chrome_test_util::TapWebViewElementWithId(linkID); |   99   chrome_test_util::TapWebViewElementWithId(linkID); | 
|  100   [[GREYCondition |  100   [ChromeEarlGrey waitForWebViewContainingText:"Click done"]; | 
|  101       conditionWithName:@"Waiting for webview to display 'Click done'." |  | 
|  102                   block:^BOOL { |  | 
|  103                     id<GREYMatcher> webViewMatcher = |  | 
|  104                         chrome_test_util::WebViewContainingText("Click done"); |  | 
|  105                     NSError* error = nil; |  | 
|  106                     [[EarlGrey selectElementWithMatcher:webViewMatcher] |  | 
|  107                         assertWithMatcher:grey_notNil() |  | 
|  108                                     error:&error]; |  | 
|  109                     return error == nil; |  | 
|  110                   }] waitWithTimeout:kConditionTimeout]; |  | 
|  111  |  101  | 
|  112   // Check that no navigation occurred and no new tabs were opened. |  102   // Check that no navigation occurred and no new tabs were opened. | 
|  113   chrome_test_util::AssertMainTabCount(1U); |  103   chrome_test_util::AssertMainTabCount(1U); | 
|  114   const GURL& currentURL = |  104   const GURL& currentURL = | 
|  115       chrome_test_util::GetCurrentWebState()->GetVisibleURL(); |  105       chrome_test_util::GetCurrentWebState()->GetVisibleURL(); | 
|  116   GREYAssert(currentURL == testURL, @"Page navigated unexpectedly %s", |  106   GREYAssert(currentURL == testURL, @"Page navigated unexpectedly %s", | 
|  117              currentURL.spec().c_str()); |  107              currentURL.spec().c_str()); | 
|  118 } |  108 } | 
|  119  |  109  | 
|  120 // Taps a link with onclick="event.preventDefault()" and target="_blank" and |  110 // Taps a link with onclick="event.preventDefault()" and target="_blank" and | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  142   web::test::SetUpFileBasedHttpServer(); |  132   web::test::SetUpFileBasedHttpServer(); | 
|  143  |  133  | 
|  144   const GURL testURL = GetTestUrl(); |  134   const GURL testURL = GetTestUrl(); | 
|  145   [ChromeEarlGrey loadURL:testURL]; |  135   [ChromeEarlGrey loadURL:testURL]; | 
|  146   chrome_test_util::AssertMainTabCount(1U); |  136   chrome_test_util::AssertMainTabCount(1U); | 
|  147  |  137  | 
|  148   // Tap on the test link. |  138   // Tap on the test link. | 
|  149   const std::string linkID = |  139   const std::string linkID = | 
|  150       "webScenarioBrowsingLinkPreventDefaultOverridesWindowOpen"; |  140       "webScenarioBrowsingLinkPreventDefaultOverridesWindowOpen"; | 
|  151   chrome_test_util::TapWebViewElementWithId(linkID); |  141   chrome_test_util::TapWebViewElementWithId(linkID); | 
|  152  |  142   [ChromeEarlGrey waitForWebViewContainingText:"Click done"]; | 
|  153   // Stall a bit to make sure the webview doesn't do anything asynchronously. |  | 
|  154   [[GREYCondition |  | 
|  155       conditionWithName:@"Waiting for webview to display 'Click done'." |  | 
|  156                   block:^BOOL { |  | 
|  157                     id<GREYMatcher> webViewMatcher = |  | 
|  158                         chrome_test_util::WebViewContainingText("Click done"); |  | 
|  159                     NSError* error = nil; |  | 
|  160                     [[EarlGrey selectElementWithMatcher:webViewMatcher] |  | 
|  161                         assertWithMatcher:grey_notNil() |  | 
|  162                                     error:&error]; |  | 
|  163                     return error == nil; |  | 
|  164                   }] waitWithTimeout:kConditionTimeout]; |  | 
|  165  |  143  | 
|  166   // Check that the tab navigated to about:blank and no new tabs were opened. |  144   // Check that the tab navigated to about:blank and no new tabs were opened. | 
|  167   [[GREYCondition |  145   [[GREYCondition | 
|  168       conditionWithName:@"Wait for navigation to about:blank" |  146       conditionWithName:@"Wait for navigation to about:blank" | 
|  169                   block:^BOOL { |  147                   block:^BOOL { | 
|  170                     const GURL& currentURL = |  148                     const GURL& currentURL = | 
|  171                         chrome_test_util::GetCurrentWebState()->GetVisibleURL(); |  149                         chrome_test_util::GetCurrentWebState()->GetVisibleURL(); | 
|  172                     return currentURL == GURL(url::kAboutBlankURL); |  150                     return currentURL == GURL(url::kAboutBlankURL); | 
|  173                   }] waitWithTimeout:kConditionTimeout]; |  151                   }] waitWithTimeout:kConditionTimeout]; | 
|  174   chrome_test_util::AssertMainTabCount(1U); |  152   chrome_test_util::AssertMainTabCount(1U); | 
|  175 } |  153 } | 
|  176  |  154  | 
|  177 @end |  155 @end | 
| OLD | NEW |