| 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/strings/sys_string_conversions.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "ios/chrome/browser/ui/ui_util.h" | 12 #include "ios/chrome/browser/ui/ui_util.h" |
| 12 #include "ios/chrome/test/app/navigation_test_util.h" | 13 #include "ios/chrome/test/app/navigation_test_util.h" |
| 13 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 14 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 15 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 15 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 16 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 16 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 17 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 17 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 18 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 18 #import "ios/third_party/material_components_ios/src/components/ProgressView/src
/MaterialProgressView.h" | 19 #import "ios/third_party/material_components_ios/src/components/ProgressView/src
/MaterialProgressView.h" |
| 19 #import "ios/web/public/test/http_server.h" | 20 #import "ios/web/public/test/http_server.h" |
| 20 #import "ios/web/public/test/http_server_util.h" | 21 #import "ios/web/public/test/http_server_util.h" |
| 21 #include "ios/web/public/test/response_providers/html_response_provider.h" | 22 #include "ios/web/public/test/response_providers/html_response_provider.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 25 using base::SysUTF8ToNSString; |
| 24 using chrome_test_util::WebViewContainingText; | 26 using chrome_test_util::WebViewContainingText; |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // Text to display in form page. | 30 // Text to display in form page. |
| 29 const char kFormPageText[] = "Form testing page"; | 31 const char kFormPageText[] = "Form testing page"; |
| 30 | 32 |
| 31 // Text to display in infinite loading page. | 33 // Text to display in infinite loading page. |
| 32 const char kPageText[] = "Navigation testing page"; | 34 const char kPageText[] = "Navigation testing page"; |
| 33 | 35 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const GURL infinitePendingURL = | 144 const GURL infinitePendingURL = |
| 143 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); | 145 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); |
| 144 web::test::SetUpHttpServer( | 146 web::test::SetUpHttpServer( |
| 145 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 147 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 146 | 148 |
| 147 // The page being loaded never completes, so call the LoadUrl helper that | 149 // The page being loaded never completes, so call the LoadUrl helper that |
| 148 // does not wait for the page to complete loading. | 150 // does not wait for the page to complete loading. |
| 149 chrome_test_util::LoadUrl(infinitePendingURL); | 151 chrome_test_util::LoadUrl(infinitePendingURL); |
| 150 | 152 |
| 151 // Wait until the page is half loaded. | 153 // Wait until the page is half loaded. |
| 152 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 154 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kPageText)]; |
| 153 assertWithMatcher:grey_notNil()]; | |
| 154 | 155 |
| 155 // Verify progress view visible and halfway progress. | 156 // Verify progress view visible and halfway progress. |
| 156 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] | 157 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 157 assertWithMatcher:grey_sufficientlyVisible()]; | 158 assertWithMatcher:grey_sufficientlyVisible()]; |
| 158 | 159 |
| 159 [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 160 [ChromeEarlGreyUI waitForToolbarVisible:YES]; |
| 160 } | 161 } |
| 161 | 162 |
| 162 // Tests that the progress indicator is shown and has expected progress value | 163 // Tests that the progress indicator is shown and has expected progress value |
| 163 // after a form is submitted, and the toolbar is visible. | 164 // after a form is submitted, and the toolbar is visible. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 175 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; | 176 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; |
| 176 web::test::SetUpSimpleHttpServer(responses); | 177 web::test::SetUpSimpleHttpServer(responses); |
| 177 | 178 |
| 178 // Add responseProvider for page that never finishes loading. | 179 // Add responseProvider for page that never finishes loading. |
| 179 web::test::AddResponseProvider( | 180 web::test::AddResponseProvider( |
| 180 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 181 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 181 | 182 |
| 182 // Load form first. | 183 // Load form first. |
| 183 [ChromeEarlGrey loadURL:formURL]; | 184 [ChromeEarlGrey loadURL:formURL]; |
| 184 | 185 |
| 186 // TODO(crbug.com/707009): Replace this matcher with |
| 187 // [ChromeEarlGrey waitForWebViewContainingText]. |
| 185 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 188 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] |
| 186 assertWithMatcher:grey_notNil()]; | 189 assertWithMatcher:grey_notNil()]; |
| 187 | 190 |
| 188 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 191 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 189 | 192 |
| 190 // Wait until the page is half loaded. | 193 // Wait until the page is half loaded. |
| 194 // TODO(crbug.com/707009): Replace this matcher with |
| 195 // [ChromeEarlGrey waitForWebViewContainingText]. |
| 191 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 196 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] |
| 192 assertWithMatcher:grey_notNil()]; | 197 assertWithMatcher:grey_notNil()]; |
| 193 | 198 |
| 194 // Verify progress view visible and halfway progress. | 199 // Verify progress view visible and halfway progress. |
| 195 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] | 200 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 196 assertWithMatcher:grey_sufficientlyVisible()]; | 201 assertWithMatcher:grey_sufficientlyVisible()]; |
| 197 | 202 |
| 198 [ChromeEarlGreyUI waitForToolbarVisible:YES]; | 203 [ChromeEarlGreyUI waitForToolbarVisible:YES]; |
| 199 } | 204 } |
| 200 | 205 |
| 201 // Tests that the progress indicator disappears after form has been submitted. | 206 // Tests that the progress indicator disappears after form has been submitted. |
| 202 - (void)testProgressIndicatorDisappearsAfterFormSubmit { | 207 - (void)testProgressIndicatorDisappearsAfterFormSubmit { |
| 203 if (IsIPadIdiom()) { | 208 if (IsIPadIdiom()) { |
| 204 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 209 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 205 } | 210 } |
| 206 | 211 |
| 207 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 212 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 208 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); | 213 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); |
| 209 | 214 |
| 210 // Create a page with a form to test. | 215 // Create a page with a form to test. |
| 211 std::map<GURL, std::string> responses; | 216 std::map<GURL, std::string> responses; |
| 212 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; | 217 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; |
| 213 responses[simplePageURL] = kPageText; | 218 responses[simplePageURL] = kPageText; |
| 214 web::test::SetUpSimpleHttpServer(responses); | 219 web::test::SetUpSimpleHttpServer(responses); |
| 215 | 220 |
| 216 [ChromeEarlGrey loadURL:formURL]; | 221 [ChromeEarlGrey loadURL:formURL]; |
| 217 | 222 |
| 218 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 223 [ChromeEarlGrey |
| 219 assertWithMatcher:grey_notNil()]; | 224 waitForWebViewContainingText:SysUTF8ToNSString(kFormPageText)]; |
| 220 | 225 |
| 221 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 226 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 222 | 227 |
| 223 // Verify the new page has been loaded. | 228 // Verify the new page has been loaded. |
| 224 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] | 229 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kPageText)]; |
| 225 assertWithMatcher:grey_notNil()]; | |
| 226 | 230 |
| 227 // Verify progress view is not visible. | 231 // Verify progress view is not visible. |
| 228 [[EarlGrey selectElementWithMatcher:ProgressView()] | 232 [[EarlGrey selectElementWithMatcher:ProgressView()] |
| 229 assertWithMatcher:grey_notVisible()]; | 233 assertWithMatcher:grey_notVisible()]; |
| 230 } | 234 } |
| 231 | 235 |
| 232 // Tests that the progress indicator disappears after form post attempt with a | 236 // Tests that the progress indicator disappears after form post attempt with a |
| 233 // submit event that returns false. | 237 // submit event that returns false. |
| 234 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { | 238 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { |
| 235 if (IsIPadIdiom()) { | 239 if (IsIPadIdiom()) { |
| 236 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 240 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 237 } | 241 } |
| 238 | 242 |
| 239 // Create a page with a form to test. | 243 // Create a page with a form to test. |
| 240 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 244 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 241 std::map<GURL, std::string> responses; | 245 std::map<GURL, std::string> responses; |
| 242 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; | 246 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; |
| 243 web::test::SetUpSimpleHttpServer(responses); | 247 web::test::SetUpSimpleHttpServer(responses); |
| 244 | 248 |
| 245 [ChromeEarlGrey loadURL:formURL]; | 249 [ChromeEarlGrey loadURL:formURL]; |
| 246 | 250 |
| 247 // Verify the form page has been loaded. | 251 // Verify the form page has been loaded. |
| 248 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] | 252 [ChromeEarlGrey |
| 249 assertWithMatcher:grey_notNil()]; | 253 waitForWebViewContainingText:SysUTF8ToNSString(kFormPageText)]; |
| 250 | 254 |
| 251 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 255 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 252 | 256 |
| 253 // Verify progress view is not visible. | 257 // Verify progress view is not visible. |
| 254 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] | 258 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] |
| 255 assertWithMatcher:grey_notVisible()]; | 259 assertWithMatcher:grey_notVisible()]; |
| 256 } | 260 } |
| 257 | 261 |
| 258 @end | 262 @end |
| OLD | NEW |