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 #include <map> | 5 #include <map> |
6 #include <memory> | 6 #include <memory> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #import <EarlGrey/EarlGrey.h> | 9 #import <EarlGrey/EarlGrey.h> |
10 #import <XCTest/XCTest.h> | 10 #import <XCTest/XCTest.h> |
11 | 11 |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #import "ios/chrome/test/app/chrome_test_util.h" | 14 #import "ios/chrome/test/app/chrome_test_util.h" |
15 #import "ios/chrome/test/app/tab_test_util.h" | 15 #import "ios/chrome/test/app/tab_test_util.h" |
16 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 16 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
17 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 17 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
18 #include "ios/web/public/test/http_server.h" | 18 #include "ios/web/public/test/http_server.h" |
19 #include "ios/web/public/test/http_server_util.h" | 19 #include "ios/web/public/test/http_server_util.h" |
20 #include "ios/web/public/test/response_providers/html_response_provider.h" | 20 #include "ios/web/public/test/response_providers/html_response_provider.h" |
21 #include "ios/web/public/test/response_providers/response_provider.h" | 21 #include "ios/web/public/test/response_providers/response_provider.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." |
| 26 #endif |
| 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const char kTestUrlNormalBrowsing[] = "http://choux/normal/browsing"; | 30 const char kTestUrlNormalBrowsing[] = "http://choux/normal/browsing"; |
27 const char kTestUrlNormalSetCookie[] = "http://choux/normal/set_cookie"; | 31 const char kTestUrlNormalSetCookie[] = "http://choux/normal/set_cookie"; |
28 const char kTestUrlIncognitoBrowsing[] = "http://choux/incognito/browsing"; | 32 const char kTestUrlIncognitoBrowsing[] = "http://choux/incognito/browsing"; |
29 const char kTestUrlIncognitoSetCookie[] = "http://choux/incognito/set_cookie"; | 33 const char kTestUrlIncognitoSetCookie[] = "http://choux/incognito/set_cookie"; |
30 | 34 |
31 const char kTestResponse[] = "fleur"; | 35 const char kTestResponse[] = "fleur"; |
32 NSString* const kNormalCookieName = @"request"; | 36 NSString* const kNormalCookieName = @"request"; |
33 NSString* const kNormalCookieValue = @"pony"; | 37 NSString* const kNormalCookieValue = @"pony"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 [ChromeEarlGrey | 80 [ChromeEarlGrey |
77 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 81 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
78 NSString* const clearCookieScript = | 82 NSString* const clearCookieScript = |
79 @"var cookies = document.cookie.split(';');" | 83 @"var cookies = document.cookie.split(';');" |
80 "for (var i = 0; i < cookies.length; i++) {" | 84 "for (var i = 0; i < cookies.length; i++) {" |
81 " var cookie = cookies[i];" | 85 " var cookie = cookies[i];" |
82 " var eqPos = cookie.indexOf('=');" | 86 " var eqPos = cookie.indexOf('=');" |
83 " var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;" | 87 " var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;" |
84 " document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';" | 88 " document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';" |
85 "}"; | 89 "}"; |
86 NSError* error = nil; | 90 __unsafe_unretained NSError* error = nil; |
87 chrome_test_util::ExecuteJavaScript(clearCookieScript, &error); | 91 chrome_test_util::ExecuteJavaScript(clearCookieScript, &error); |
88 [super tearDown]; | 92 [super tearDown]; |
89 } | 93 } |
90 | 94 |
91 #pragma mark - Tests | 95 #pragma mark - Tests |
92 | 96 |
93 // Tests toggling between Normal tabs and Incognito tabs. Different cookies | 97 // Tests toggling between Normal tabs and Incognito tabs. Different cookies |
94 // (request=pony for normal tabs, secret=rainbow for incognito tabs) are set. | 98 // (request=pony for normal tabs, secret=rainbow for incognito tabs) are set. |
95 // The goal is to verify that cookies set in incognito tabs are available in | 99 // The goal is to verify that cookies set in incognito tabs are available in |
96 // incognito tabs but not available in normal tabs. Cookies set in incognito | 100 // incognito tabs but not available in normal tabs. Cookies set in incognito |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 273 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
270 cookies = [ChromeEarlGrey cookies]; | 274 cookies = [ChromeEarlGrey cookies]; |
271 GREYAssertEqualObjects( | 275 GREYAssertEqualObjects( |
272 kNormalCookieValue, cookies[kNormalCookieName], | 276 kNormalCookieValue, cookies[kNormalCookieName], |
273 @"Normal cookie should still be found in normal mode."); | 277 @"Normal cookie should still be found in normal mode."); |
274 GREYAssertEqual(1U, cookies.count, | 278 GREYAssertEqual(1U, cookies.count, |
275 @"Only one cookie should be found in normal mode."); | 279 @"Only one cookie should be found in normal mode."); |
276 } | 280 } |
277 | 281 |
278 @end | 282 @end |
OLD | NEW |