| 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 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const GURL infinitePendingURL = | 145 const GURL infinitePendingURL = |
| 146 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); | 146 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); |
| 147 web::test::SetUpHttpServer( | 147 web::test::SetUpHttpServer( |
| 148 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 148 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 149 | 149 |
| 150 // The page being loaded never completes, so call the LoadUrl helper that | 150 // The page being loaded never completes, so call the LoadUrl helper that |
| 151 // does not wait for the page to complete loading. | 151 // does not wait for the page to complete loading. |
| 152 chrome_test_util::LoadUrl(infinitePendingURL); | 152 chrome_test_util::LoadUrl(infinitePendingURL); |
| 153 | 153 |
| 154 // Wait until the page is half loaded. | 154 // Wait until the page is half loaded. |
| 155 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 155 [ChromeEarlGrey waitForWebViewContainingText:kPageText]; |
| 156 assertWithMatcher:grey_notNil()]; | |
| 157 | 156 |
| 158 // Verify progress view visible and halfway progress. | 157 // Verify progress view visible and halfway progress. |
| 159 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] | 158 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 160 assertWithMatcher:grey_sufficientlyVisible()]; | 159 assertWithMatcher:grey_sufficientlyVisible()]; |
| 161 | 160 |
| 162 [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 161 [ChromeEarlGreyUI waitForToolbarVisible:YES]; |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Tests that the progress indicator is shown and has expected progress value | 164 // Tests that the progress indicator is shown and has expected progress value |
| 166 // after a form is submitted, and the toolbar is visible. | 165 // after a form is submitted, and the toolbar is visible. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 178 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; | 177 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; |
| 179 web::test::SetUpSimpleHttpServer(responses); | 178 web::test::SetUpSimpleHttpServer(responses); |
| 180 | 179 |
| 181 // Add responseProvider for page that never finishes loading. | 180 // Add responseProvider for page that never finishes loading. |
| 182 web::test::AddResponseProvider( | 181 web::test::AddResponseProvider( |
| 183 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 182 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 184 | 183 |
| 185 // Load form first. | 184 // Load form first. |
| 186 [ChromeEarlGrey loadURL:formURL]; | 185 [ChromeEarlGrey loadURL:formURL]; |
| 187 | 186 |
| 187 // TODO(crbug.com/707009): Replace this matcher with |
| 188 // [ChromeEarlGrey waitForWebViewContainingText]. It fails to synchronize with |
| 189 // the progress bar. |
| 188 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 190 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] |
| 189 assertWithMatcher:grey_notNil()]; | 191 assertWithMatcher:grey_notNil()]; |
| 190 | 192 |
| 191 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 193 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 192 | 194 |
| 193 // Wait until the page is half loaded. | 195 // Wait until the page is half loaded. |
| 196 // TODO(crbug.com/707009): Replace this matcher with |
| 197 // [ChromeEarlGrey waitForWebViewContainingText]. |
| 194 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 198 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] |
| 195 assertWithMatcher:grey_notNil()]; | 199 assertWithMatcher:grey_notNil()]; |
| 196 | 200 |
| 197 // Verify progress view visible and halfway progress. | 201 // Verify progress view visible and halfway progress. |
| 198 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] | 202 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 199 assertWithMatcher:grey_sufficientlyVisible()]; | 203 assertWithMatcher:grey_sufficientlyVisible()]; |
| 200 | 204 |
| 201 [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 205 [ChromeEarlGreyUI waitForToolbarVisible:YES]; |
| 202 } | 206 } |
| 203 | 207 |
| 204 // Tests that the progress indicator disappears after form has been submitted. | 208 // Tests that the progress indicator disappears after form has been submitted. |
| 205 - (void)testProgressIndicatorDisappearsAfterFormSubmit { | 209 - (void)testProgressIndicatorDisappearsAfterFormSubmit { |
| 206 if (IsIPadIdiom()) { | 210 if (IsIPadIdiom()) { |
| 207 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 211 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 208 } | 212 } |
| 209 | 213 |
| 210 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 214 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 211 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); | 215 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); |
| 212 | 216 |
| 213 // Create a page with a form to test. | 217 // Create a page with a form to test. |
| 214 std::map<GURL, std::string> responses; | 218 std::map<GURL, std::string> responses; |
| 215 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; | 219 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; |
| 216 responses[simplePageURL] = kPageText; | 220 responses[simplePageURL] = kPageText; |
| 217 web::test::SetUpSimpleHttpServer(responses); | 221 web::test::SetUpSimpleHttpServer(responses); |
| 218 | 222 |
| 219 [ChromeEarlGrey loadURL:formURL]; | 223 [ChromeEarlGrey loadURL:formURL]; |
| 220 | 224 |
| 221 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 225 [ChromeEarlGrey waitForWebViewContainingText:kFormPageText]; |
| 222 assertWithMatcher:grey_notNil()]; | |
| 223 | 226 |
| 224 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 227 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 225 | 228 |
| 226 // Verify the new page has been loaded. | 229 // Verify the new page has been loaded. |
| 227 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 230 [ChromeEarlGrey waitForWebViewContainingText:kPageText]; |
| 228 assertWithMatcher:grey_notNil()]; | |
| 229 | 231 |
| 230 // Verify progress view is not visible. | 232 // Verify progress view is not visible. |
| 231 [[EarlGrey selectElementWithMatcher:ProgressView()] | 233 [[EarlGrey selectElementWithMatcher:ProgressView()] |
| 232 assertWithMatcher:grey_notVisible()]; | 234 assertWithMatcher:grey_notVisible()]; |
| 233 } | 235 } |
| 234 | 236 |
| 235 // Tests that the progress indicator disappears after form post attempt with a | 237 // Tests that the progress indicator disappears after form post attempt with a |
| 236 // submit event that returns false. | 238 // submit event that returns false. |
| 237 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { | 239 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { |
| 238 if (IsIPadIdiom()) { | 240 if (IsIPadIdiom()) { |
| 239 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 241 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 240 } | 242 } |
| 241 | 243 |
| 242 // Create a page with a form to test. | 244 // Create a page with a form to test. |
| 243 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 245 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 244 std::map<GURL, std::string> responses; | 246 std::map<GURL, std::string> responses; |
| 245 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; | 247 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; |
| 246 web::test::SetUpSimpleHttpServer(responses); | 248 web::test::SetUpSimpleHttpServer(responses); |
| 247 | 249 |
| 248 [ChromeEarlGrey loadURL:formURL]; | 250 [ChromeEarlGrey loadURL:formURL]; |
| 249 | 251 |
| 250 // Verify the form page has been loaded. | 252 // Verify the form page has been loaded. |
| 251 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 253 [ChromeEarlGrey waitForWebViewContainingText:kFormPageText]; |
| 252 assertWithMatcher:grey_notNil()]; | |
| 253 | 254 |
| 254 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 255 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 255 | 256 |
| 256 // Verify progress view is not visible. | 257 // Verify progress view is not visible. |
| 257 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] | 258 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] |
| 258 assertWithMatcher:grey_notVisible()]; | 259 assertWithMatcher:grey_notVisible()]; |
| 259 } | 260 } |
| 260 | 261 |
| 261 @end | 262 @end |
| OLD | NEW |