| 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" |
| 11 #include "ios/chrome/browser/ui/ui_util.h" | 11 #include "ios/chrome/browser/ui/ui_util.h" |
| 12 #include "ios/chrome/test/app/navigation_test_util.h" | 12 #include "ios/chrome/test/app/navigation_test_util.h" |
| 13 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 13 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 17 #include "ios/chrome/test/earl_grey/chrome_util.h" | 17 #include "ios/chrome/test/earl_grey/chrome_util.h" |
| 18 #import "ios/testing/earl_grey/disabled_test_macros.h" | 18 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| 19 #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" |
| 20 #import "ios/web/public/test/http_server.h" | 20 #import "ios/web/public/test/http_server.h" |
| 21 #import "ios/web/public/test/http_server_util.h" | 21 #import "ios/web/public/test/http_server_util.h" |
| 22 #include "ios/web/public/test/response_providers/html_response_provider.h" | 22 #include "ios/web/public/test/response_providers/html_response_provider.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 using chrome_test_util::webViewContainingText; | 25 using chrome_test_util::WebViewContainingText; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Text to display in form page. | 29 // Text to display in form page. |
| 30 const char kFormPageText[] = "Form testing page"; | 30 const char kFormPageText[] = "Form testing page"; |
| 31 | 31 |
| 32 // Text to display in infinite loading page. | 32 // Text to display in infinite loading page. |
| 33 const char kPageText[] = "Navigation testing page"; | 33 const char kPageText[] = "Navigation testing page"; |
| 34 | 34 |
| 35 // Identifier of form to submit on form page. | 35 // Identifier of form to submit on form page. |
| 36 const char kFormID[] = "testform"; | 36 const char kFormID[] = "testform"; |
| 37 | 37 |
| 38 // URL string for a form page. | 38 // URL string for a form page. |
| 39 const char kFormURL[] = "http://form"; | 39 const char kFormURL[] = "http://form"; |
| 40 | 40 |
| 41 // URL string for an infinite pending page. | 41 // URL string for an infinite pending page. |
| 42 const char kInfinitePendingPageURL[] = "http://infinite"; | 42 const char kInfinitePendingPageURL[] = "http://infinite"; |
| 43 | 43 |
| 44 // URL string for a simple page containing |kPageText|. | 44 // URL string for a simple page containing |kPageText|. |
| 45 const char kSimplePageURL[] = "http://simplepage"; | 45 const char kSimplePageURL[] = "http://simplepage"; |
| 46 | 46 |
| 47 // Matcher for progress view. | 47 // Matcher for progress view. |
| 48 id<GREYMatcher> progressView() { | 48 id<GREYMatcher> ProgressView() { |
| 49 return grey_kindOfClass([MDCProgressView class]); | 49 return grey_kindOfClass([MDCProgressView class]); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Matcher for the progress view with |progress|. | 52 // Matcher for the progress view with |progress|. |
| 53 id<GREYMatcher> progressViewWithProgress(CGFloat progress) { | 53 id<GREYMatcher> ProgressViewWithProgress(CGFloat progress) { |
| 54 MatchesBlock matches = ^BOOL(UIView* view) { | 54 MatchesBlock matches = ^BOOL(UIView* view) { |
| 55 MDCProgressView* progressView = base::mac::ObjCCast<MDCProgressView>(view); | 55 MDCProgressView* progressView = base::mac::ObjCCast<MDCProgressView>(view); |
| 56 return progressView && progressView.progress == progress; | 56 return progressView && progressView.progress == progress; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 DescribeToBlock describe = ^(id<GREYDescription> description) { | 59 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 60 [description | 60 [description |
| 61 appendText:[NSString stringWithFormat:@"progress view with progress:%f", | 61 appendText:[NSString stringWithFormat:@"progress view with progress:%f", |
| 62 progress]]; | 62 progress]]; |
| 63 }; | 63 }; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const GURL infinitePendingURL = | 143 const GURL infinitePendingURL = |
| 144 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); | 144 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); |
| 145 web::test::SetUpHttpServer( | 145 web::test::SetUpHttpServer( |
| 146 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 146 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 147 | 147 |
| 148 // The page being loaded never completes, so call the LoadUrl helper that | 148 // The page being loaded never completes, so call the LoadUrl helper that |
| 149 // does not wait for the page to complete loading. | 149 // does not wait for the page to complete loading. |
| 150 chrome_test_util::LoadUrl(infinitePendingURL); | 150 chrome_test_util::LoadUrl(infinitePendingURL); |
| 151 | 151 |
| 152 // Wait until the page is half loaded. | 152 // Wait until the page is half loaded. |
| 153 [[EarlGrey selectElementWithMatcher:webViewContainingText(kPageText)] | 153 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] |
| 154 assertWithMatcher:grey_notNil()]; | 154 assertWithMatcher:grey_notNil()]; |
| 155 | 155 |
| 156 // Verify progress view visible and halfway progress. | 156 // Verify progress view visible and halfway progress. |
| 157 [[EarlGrey selectElementWithMatcher:progressViewWithProgress(0.5)] | 157 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 158 assertWithMatcher:grey_sufficientlyVisible()]; | 158 assertWithMatcher:grey_sufficientlyVisible()]; |
| 159 | 159 |
| 160 // Verify toolbar visible. | 160 // Verify toolbar visible. |
| 161 chrome_test_util::AssertToolbarVisible(); | 161 chrome_test_util::AssertToolbarVisible(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // 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 |
| 165 // after a form is submitted, and the toolbar is visible. | 165 // after a form is submitted, and the toolbar is visible. |
| 166 - (void)testProgressIndicatorShownOnFormSubmit { | 166 - (void)testProgressIndicatorShownOnFormSubmit { |
| 167 if (IsIPadIdiom()) { | 167 if (IsIPadIdiom()) { |
| 168 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 168 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 169 } | 169 } |
| 170 | 170 |
| 171 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 171 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 172 const GURL infinitePendingURL = | 172 const GURL infinitePendingURL = |
| 173 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); | 173 web::test::HttpServer::MakeUrl(kInfinitePendingPageURL); |
| 174 | 174 |
| 175 // Create a page with a form to test. | 175 // Create a page with a form to test. |
| 176 std::map<GURL, std::string> responses; | 176 std::map<GURL, std::string> responses; |
| 177 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; | 177 responses[formURL] = [self formPageHTMLWithFormSubmitURL:infinitePendingURL]; |
| 178 web::test::SetUpSimpleHttpServer(responses); | 178 web::test::SetUpSimpleHttpServer(responses); |
| 179 | 179 |
| 180 // Add responseProvider for page that never finishes loading. | 180 // Add responseProvider for page that never finishes loading. |
| 181 web::test::AddResponseProvider( | 181 web::test::AddResponseProvider( |
| 182 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); | 182 base::MakeUnique<InfinitePendingResponseProvider>(infinitePendingURL)); |
| 183 | 183 |
| 184 // Load form first. | 184 // Load form first. |
| 185 [ChromeEarlGrey loadURL:formURL]; | 185 [ChromeEarlGrey loadURL:formURL]; |
| 186 | 186 |
| 187 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFormPageText)] | 187 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] |
| 188 assertWithMatcher:grey_notNil()]; | 188 assertWithMatcher:grey_notNil()]; |
| 189 | 189 |
| 190 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 190 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 191 | 191 |
| 192 // Wait until the page is half loaded. | 192 // Wait until the page is half loaded. |
| 193 [[EarlGrey selectElementWithMatcher:webViewContainingText(kPageText)] | 193 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] |
| 194 assertWithMatcher:grey_notNil()]; | 194 assertWithMatcher:grey_notNil()]; |
| 195 | 195 |
| 196 // Verify progress view visible and halfway progress. | 196 // Verify progress view visible and halfway progress. |
| 197 [[EarlGrey selectElementWithMatcher:progressViewWithProgress(0.5)] | 197 [[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] |
| 198 assertWithMatcher:grey_sufficientlyVisible()]; | 198 assertWithMatcher:grey_sufficientlyVisible()]; |
| 199 | 199 |
| 200 // Verify toolbar visible. | 200 // Verify toolbar visible. |
| 201 chrome_test_util::AssertToolbarVisible(); | 201 chrome_test_util::AssertToolbarVisible(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 // Tests that the progress indicator disappears after form has been submitted. | 204 // Tests that the progress indicator disappears after form has been submitted. |
| 205 - (void)testProgressIndicatorDisappearsAfterFormSubmit { | 205 - (void)testProgressIndicatorDisappearsAfterFormSubmit { |
| 206 if (IsIPadIdiom()) { | 206 if (IsIPadIdiom()) { |
| 207 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 207 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 208 } | 208 } |
| 209 | 209 |
| 210 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 210 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 211 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); | 211 const GURL simplePageURL = web::test::HttpServer::MakeUrl(kSimplePageURL); |
| 212 | 212 |
| 213 // Create a page with a form to test. | 213 // Create a page with a form to test. |
| 214 std::map<GURL, std::string> responses; | 214 std::map<GURL, std::string> responses; |
| 215 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; | 215 responses[formURL] = [self formPageHTMLWithFormSubmitURL:simplePageURL]; |
| 216 responses[simplePageURL] = kPageText; | 216 responses[simplePageURL] = kPageText; |
| 217 web::test::SetUpSimpleHttpServer(responses); | 217 web::test::SetUpSimpleHttpServer(responses); |
| 218 | 218 |
| 219 [ChromeEarlGrey loadURL:formURL]; | 219 [ChromeEarlGrey loadURL:formURL]; |
| 220 | 220 |
| 221 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFormPageText)] | 221 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] |
| 222 assertWithMatcher:grey_notNil()]; | 222 assertWithMatcher:grey_notNil()]; |
| 223 | 223 |
| 224 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 224 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 225 | 225 |
| 226 // Verify the new page has been loaded. | 226 // Verify the new page has been loaded. |
| 227 [[EarlGrey selectElementWithMatcher:webViewContainingText(kPageText)] | 227 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kPageText)] |
| 228 assertWithMatcher:grey_notNil()]; | 228 assertWithMatcher:grey_notNil()]; |
| 229 | 229 |
| 230 // Verify progress view is not visible. | 230 // Verify progress view is not visible. |
| 231 [[EarlGrey selectElementWithMatcher:progressView()] | 231 [[EarlGrey selectElementWithMatcher:ProgressView()] |
| 232 assertWithMatcher:grey_notVisible()]; | 232 assertWithMatcher:grey_notVisible()]; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Tests that the progress indicator disappears after form post attempt with a | 235 // Tests that the progress indicator disappears after form post attempt with a |
| 236 // submit event that returns false. | 236 // submit event that returns false. |
| 237 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { | 237 - (void)testProgressIndicatorDisappearsAfterSuppressedFormPost { |
| 238 if (IsIPadIdiom()) { | 238 if (IsIPadIdiom()) { |
| 239 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); | 239 EARL_GREY_TEST_SKIPPED(@"Skipped for iPad (no progress view in tablet)"); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Create a page with a form to test. | 242 // Create a page with a form to test. |
| 243 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); | 243 const GURL formURL = web::test::HttpServer::MakeUrl(kFormURL); |
| 244 std::map<GURL, std::string> responses; | 244 std::map<GURL, std::string> responses; |
| 245 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; | 245 responses[formURL] = [self formPageHTMLWithSuppressedSubmitEvent]; |
| 246 web::test::SetUpSimpleHttpServer(responses); | 246 web::test::SetUpSimpleHttpServer(responses); |
| 247 | 247 |
| 248 [ChromeEarlGrey loadURL:formURL]; | 248 [ChromeEarlGrey loadURL:formURL]; |
| 249 | 249 |
| 250 // Verify the form page has been loaded. | 250 // Verify the form page has been loaded. |
| 251 [[EarlGrey selectElementWithMatcher:webViewContainingText(kFormPageText)] | 251 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kFormPageText)] |
| 252 assertWithMatcher:grey_notNil()]; | 252 assertWithMatcher:grey_notNil()]; |
| 253 | 253 |
| 254 chrome_test_util::SubmitWebViewFormWithId(kFormID); | 254 chrome_test_util::SubmitWebViewFormWithId(kFormID); |
| 255 | 255 |
| 256 // Verify progress view is not visible. | 256 // Verify progress view is not visible. |
| 257 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] | 257 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] |
| 258 assertWithMatcher:grey_notVisible()]; | 258 assertWithMatcher:grey_notVisible()]; |
| 259 } | 259 } |
| 260 | 260 |
| 261 @end | 261 @end |
| OLD | NEW |