| 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> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const char kTestUrlNormalBrowsing[] = "http://choux/normal/browsing"; | 26 const char kTestUrlNormalBrowsing[] = "http://choux/normal/browsing"; |
| 27 const char kTestUrlNormalSetCookie[] = "http://choux/normal/set_cookie"; | 27 const char kTestUrlNormalSetCookie[] = "http://choux/normal/set_cookie"; |
| 28 const char kTestUrlIncognitoBrowsing[] = "http://choux/incognito/browsing"; | 28 const char kTestUrlIncognitoBrowsing[] = "http://choux/incognito/browsing"; |
| 29 const char kTestUrlIncognitoSetCookie[] = "http://choux/incognito/set_cookie"; | 29 const char kTestUrlIncognitoSetCookie[] = "http://choux/incognito/set_cookie"; |
| 30 | 30 |
| 31 const char kTestResponse[] = "fleur"; | 31 const char kTestResponse[] = "fleur"; |
| 32 NSString* const kNoCookieText = @"No cookies!"; | 32 NSString* const kNormalCookieName = @"request"; |
| 33 NSString* const kNormalCookieKey = @"request"; | |
| 34 NSString* const kNormalCookieValue = @"pony"; | 33 NSString* const kNormalCookieValue = @"pony"; |
| 35 NSString* const kIncognitoCookieKey = @"secret"; | 34 NSString* const kIncognitoCookieName = @"secret"; |
| 36 NSString* const kIncognitoCookieValue = @"rainbow"; | 35 NSString* const kIncognitoCookieValue = @"rainbow"; |
| 37 | 36 |
| 38 NSString* const kGetCookieScript = | |
| 39 @"var c = document.cookie ? document.cookie.split(/;\\s*/) : [];" | |
| 40 "if (!c.length) {" | |
| 41 " document.documentElement.innerHTML = 'No cookies!';" | |
| 42 "} else {" | |
| 43 " document.documentElement.innerHTML = 'OK: ' + c.join(',');" | |
| 44 "}"; | |
| 45 | |
| 46 // Checks that a cookie of key=value is the only cookie exists in current domain | |
| 47 // in current web state. | |
| 48 // Returns true if cookie |key| of value |value| is the only cookie that exists. | |
| 49 bool CheckCookieExists(NSString* key, NSString* value) { | |
| 50 NSError* error = nil; | |
| 51 id result = chrome_test_util::ExecuteJavaScript(kGetCookieScript, &error); | |
| 52 if (error) | |
| 53 return false; | |
| 54 NSString* stringResult = base::mac::ObjCCastStrict<NSString>(result); | |
| 55 NSString* expectedText = [NSString stringWithFormat:@"OK: %@=%@", key, value]; | |
| 56 return [stringResult isEqualToString:expectedText]; | |
| 57 } | |
| 58 | |
| 59 // Checks that there is no cookie in current domain in current web state. | |
| 60 bool CheckNoCookieExists() { | |
| 61 NSError* error = nil; | |
| 62 id result = chrome_test_util::ExecuteJavaScript(kGetCookieScript, &error); | |
| 63 if (error) | |
| 64 return false; | |
| 65 NSString* stringResult = base::mac::ObjCCastStrict<NSString>(result); | |
| 66 return [stringResult isEqualToString:kNoCookieText]; | |
| 67 } | |
| 68 | |
| 69 } // namespace | 37 } // namespace |
| 70 | 38 |
| 71 @interface CookiesTestCase : ChromeTestCase | 39 @interface CookiesTestCase : ChromeTestCase |
| 72 @end | 40 @end |
| 73 | 41 |
| 74 @implementation CookiesTestCase | 42 @implementation CookiesTestCase |
| 75 | 43 |
| 76 #pragma mark - Overrides superclass | 44 #pragma mark - Overrides superclass |
| 77 | 45 |
| 78 + (void)setUp { | 46 + (void)setUp { |
| 79 [super setUp]; | 47 [super setUp]; |
| 80 // Creates a map of canned responses and set up the test HTML server. | 48 // Creates a map of canned responses and set up the test HTML server. |
| 81 // |kTestUrlNormalSetCookie| and |kTestUrlIncognitoSetCookie| always sets | 49 // |kTestUrlNormalSetCookie| and |kTestUrlIncognitoSetCookie| always sets |
| 82 // cookie in response header while |kTestUrlNormalBrowsing| and | 50 // cookie in response header while |kTestUrlNormalBrowsing| and |
| 83 // |kTestUrlIncognitoBrowsing| doesn't. | 51 // |kTestUrlIncognitoBrowsing| doesn't. |
| 84 std::map<GURL, std::pair<std::string, std::string>> responses; | 52 std::map<GURL, std::pair<std::string, std::string>> responses; |
| 85 | 53 |
| 86 NSString* normalCookie = [NSString | 54 NSString* normalCookie = [NSString |
| 87 stringWithFormat:@"%@=%@", kNormalCookieKey, kNormalCookieValue]; | 55 stringWithFormat:@"%@=%@", kNormalCookieName, kNormalCookieValue]; |
| 88 NSString* incognitoCookie = [NSString | 56 NSString* incognitoCookie = [NSString |
| 89 stringWithFormat:@"%@=%@", kIncognitoCookieKey, kIncognitoCookieValue]; | 57 stringWithFormat:@"%@=%@", kIncognitoCookieName, kIncognitoCookieValue]; |
| 90 | 58 |
| 91 responses[web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)] = | 59 responses[web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)] = |
| 92 std::pair<std::string, std::string>("", kTestResponse); | 60 std::pair<std::string, std::string>("", kTestResponse); |
| 93 responses[web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)] = | 61 responses[web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)] = |
| 94 std::pair<std::string, std::string>(base::SysNSStringToUTF8(normalCookie), | 62 std::pair<std::string, std::string>(base::SysNSStringToUTF8(normalCookie), |
| 95 kTestResponse); | 63 kTestResponse); |
| 96 responses[web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)] = | 64 responses[web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)] = |
| 97 std::pair<std::string, std::string>("", kTestResponse); | 65 std::pair<std::string, std::string>("", kTestResponse); |
| 98 responses[web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)] = | 66 responses[web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)] = |
| 99 std::pair<std::string, std::string>( | 67 std::pair<std::string, std::string>( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 125 // Tests toggling between Normal tabs and Incognito tabs. Different cookies | 93 // Tests toggling between Normal tabs and Incognito tabs. Different cookies |
| 126 // (request=pony for normal tabs, secret=rainbow for incognito tabs) are set. | 94 // (request=pony for normal tabs, secret=rainbow for incognito tabs) are set. |
| 127 // The goal is to verify that cookies set in incognito tabs are available in | 95 // The goal is to verify that cookies set in incognito tabs are available in |
| 128 // incognito tabs but not available in normal tabs. Cookies set in incognito | 96 // incognito tabs but not available in normal tabs. Cookies set in incognito |
| 129 // tabs are also deleted when all incognito tabs are closed. | 97 // tabs are also deleted when all incognito tabs are closed. |
| 130 - (void)testClearIncognitoFromMain { | 98 - (void)testClearIncognitoFromMain { |
| 131 // Loads a dummy page in normal tab. Sets a normal test cookie. Verifies that | 99 // Loads a dummy page in normal tab. Sets a normal test cookie. Verifies that |
| 132 // the incognito test cookie is not found. | 100 // the incognito test cookie is not found. |
| 133 [ChromeEarlGrey | 101 [ChromeEarlGrey |
| 134 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; | 102 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; |
| 135 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 103 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 136 @"Failed to set normal cookie in normal mode. (1)"); | 104 GREYAssertEqualObjects(kNormalCookieValue, cookies[kNormalCookieName], |
| 137 GREYAssertFalse(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 105 @"Failed to set normal cookie in normal mode."); |
| 138 @"Incognito cookie should not be found in normal mode. (1)"); | 106 GREYAssertEqual(1U, cookies.count, |
| 107 @"Only one cookie should be found in normal mode."); |
| 139 | 108 |
| 140 // Opens an incognito tab, loads the dummy page, and sets incognito test | 109 // Opens an incognito tab, loads the dummy page, and sets incognito test |
| 141 // cookie. | 110 // cookie. |
| 142 chrome_test_util::OpenNewIncognitoTab(); | 111 chrome_test_util::OpenNewIncognitoTab(); |
| 143 [ChromeEarlGrey | 112 [ChromeEarlGrey |
| 144 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; | 113 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; |
| 145 GREYAssertTrue(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 114 cookies = [ChromeEarlGrey cookies]; |
| 146 @"Failed to set incognito cookie in incognito mode. (2)"); | 115 GREYAssertEqualObjects(kIncognitoCookieValue, cookies[kIncognitoCookieName], |
| 116 @"Failed to set incognito cookie in incognito mode."); |
| 117 GREYAssertEqual(1U, cookies.count, |
| 118 @"Only one cookie should be found in incognito mode."); |
| 147 | 119 |
| 148 // Switches back to normal profile by opening up a new tab. Test cookie | 120 // Switches back to normal profile by opening up a new tab. Test cookie |
| 149 // should not be found. | 121 // should not be found. |
| 150 chrome_test_util::OpenNewTab(); | 122 chrome_test_util::OpenNewTab(); |
| 151 [ChromeEarlGrey | 123 [ChromeEarlGrey |
| 152 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 124 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 153 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 125 cookies = [ChromeEarlGrey cookies]; |
| 154 @"Normal cookie should be found in normal mode. (3)"); | 126 GREYAssertEqualObjects(kNormalCookieValue, cookies[kNormalCookieName], |
| 155 GREYAssertFalse(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 127 @"Normal cookie should still exist in normal mode."); |
| 156 @"Incognito cookie should not be found in normal mode. (3)"); | 128 GREYAssertEqual(1U, cookies.count, |
| 129 @"Only one cookie should be found in normal mode."); |
| 157 | 130 |
| 158 // Finally, closes all incognito tabs while still in normal tab. | 131 // Finally, closes all incognito tabs while still in normal tab. |
| 159 // Checks that incognito cookie is gone. | 132 // Checks that incognito cookie is gone. |
| 160 chrome_test_util::CloseAllIncognitoTabs(); | 133 chrome_test_util::CloseAllIncognitoTabs(); |
| 161 chrome_test_util::OpenNewTab(); | 134 chrome_test_util::OpenNewTab(); |
| 162 [ChromeEarlGrey | 135 [ChromeEarlGrey |
| 163 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 136 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; |
| 164 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 137 cookies = [ChromeEarlGrey cookies]; |
| 165 @"Normal cookie should be found in normal mode. (4)"); | 138 GREYAssertEqual(0U, cookies.count, |
| 166 GREYAssertFalse(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 139 @"Incognito cookie should be gone from normal mode."); |
| 167 @"Incognito cookie should be gone from normal mode. (4)"); | |
| 168 } | 140 } |
| 169 | 141 |
| 170 // Tests that a cookie set in incognito tab is removed after closing all | 142 // Tests that a cookie set in incognito tab is removed after closing all |
| 171 // incognito tabs and then when new incognito tab is created the cookie will | 143 // incognito tabs and then when new incognito tab is created the cookie will |
| 172 // not reappear. | 144 // not reappear. |
| 173 - (void)testClearIncognitoFromIncognito { | 145 - (void)testClearIncognitoFromIncognito { |
| 174 // Loads a page in normal tab. | 146 // Loads a page in normal tab. |
| 175 [ChromeEarlGrey | 147 [ChromeEarlGrey |
| 176 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 148 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 177 | 149 |
| 178 // Opens an incognito tab, loads a page, and sets an incognito cookie. | 150 // Opens an incognito tab, loads a page, and sets an incognito cookie. |
| 179 chrome_test_util::OpenNewIncognitoTab(); | 151 chrome_test_util::OpenNewIncognitoTab(); |
| 180 [ChromeEarlGrey | 152 [ChromeEarlGrey |
| 181 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; | 153 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; |
| 182 GREYAssertTrue(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 154 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 183 @"Failed to set incognito cookie in incognito mode. (1)"); | 155 GREYAssertEqualObjects(kIncognitoCookieValue, cookies[kIncognitoCookieName], |
| 156 @"Failed to set incognito cookie in incognito mode."); |
| 157 GREYAssertEqual(1U, cookies.count, |
| 158 @"Only one cookie should be found in incognito mode."); |
| 184 | 159 |
| 185 // Closes all incognito tabs and switch back to a normal tab. | 160 // Closes all incognito tabs and switch back to a normal tab. |
| 186 chrome_test_util::CloseAllIncognitoTabs(); | 161 chrome_test_util::CloseAllIncognitoTabs(); |
| 187 chrome_test_util::OpenNewTab(); | 162 chrome_test_util::OpenNewTab(); |
| 188 [ChromeEarlGrey | 163 [ChromeEarlGrey |
| 189 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 164 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 190 | 165 |
| 191 // Opens a new incognito tab and verify that the previously set cookie | 166 // Opens a new incognito tab and verify that the previously set cookie |
| 192 // is no longer there. | 167 // is no longer there. |
| 193 chrome_test_util::OpenNewIncognitoTab(); | 168 chrome_test_util::OpenNewIncognitoTab(); |
| 194 [ChromeEarlGrey | 169 [ChromeEarlGrey |
| 195 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; | 170 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; |
| 196 GREYAssertTrue(CheckNoCookieExists(), | 171 cookies = [ChromeEarlGrey cookies]; |
| 197 @"Incognito cookie should be gone from incognito mode. (2)"); | 172 GREYAssertEqual(0U, cookies.count, |
| 173 @"Incognito cookie should be gone from incognito mode."); |
| 198 | 174 |
| 199 // Verifies that new incognito cookies can be set. | 175 // Verifies that new incognito cookies can be set. |
| 200 [ChromeEarlGrey | 176 [ChromeEarlGrey |
| 201 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; | 177 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; |
| 202 GREYAssertTrue(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 178 cookies = [ChromeEarlGrey cookies]; |
| 203 @"Failed to set incognito cookie in incognito mode. (3)"); | 179 GREYAssertEqualObjects(kIncognitoCookieValue, cookies[kIncognitoCookieName], |
| 180 @"Failed to set incognito cookie in incognito mode."); |
| 181 GREYAssertEqual(1U, cookies.count, |
| 182 @"Only one cookie should be found in incognito mode."); |
| 204 } | 183 } |
| 205 | 184 |
| 206 // Tests that a cookie set in normal tab is not available in an incognito tab. | 185 // Tests that a cookie set in normal tab is not available in an incognito tab. |
| 207 - (void)testSwitchToIncognito { | 186 - (void)testSwitchToIncognito { |
| 208 // Sets cookie in normal tab. | 187 // Sets cookie in normal tab. |
| 209 [ChromeEarlGrey | 188 [ChromeEarlGrey |
| 210 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; | 189 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; |
| 211 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 190 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 212 @"Failed to set normal cookie in normal mode. (1)"); | 191 GREYAssertEqualObjects(kNormalCookieValue, cookies[kNormalCookieName], |
| 192 @"Normal cookie should still exist in normal mode."); |
| 193 GREYAssertEqual(1U, cookies.count, |
| 194 @"Only one cookie should be found in normal mode."); |
| 213 | 195 |
| 214 // Switches to a new incognito tab and verifies that cookie is not there. | 196 // Switches to a new incognito tab and verifies that cookie is not there. |
| 215 chrome_test_util::OpenNewIncognitoTab(); | 197 chrome_test_util::OpenNewIncognitoTab(); |
| 216 [ChromeEarlGrey | 198 [ChromeEarlGrey |
| 217 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; | 199 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; |
| 218 GREYAssertTrue(CheckNoCookieExists(), | 200 cookies = [ChromeEarlGrey cookies]; |
| 219 @"Normal cookie should not be found in incognito mode. (2)"); | 201 GREYAssertEqual(0U, cookies.count, |
| 202 @"Normal cookie should not be found in incognito mode."); |
| 220 | 203 |
| 221 // Closes all incognito tabs and then switching back to a normal tab. Verifies | 204 // Closes all incognito tabs and then switching back to a normal tab. Verifies |
| 222 // that the cookie set earlier is still there. | 205 // that the cookie set earlier is still there. |
| 223 chrome_test_util::CloseAllIncognitoTabs(); | 206 chrome_test_util::CloseAllIncognitoTabs(); |
| 224 chrome_test_util::OpenNewTab(); | 207 chrome_test_util::OpenNewTab(); |
| 225 [ChromeEarlGrey | 208 [ChromeEarlGrey |
| 226 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 209 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 227 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 210 cookies = [ChromeEarlGrey cookies]; |
| 228 @"Normal cookie should still be found in normal mode. (3)"); | 211 GREYAssertEqualObjects( |
| 212 kNormalCookieValue, cookies[kNormalCookieName], |
| 213 @"Normal cookie should still be found in normal mode."); |
| 214 GREYAssertEqual(1U, cookies.count, |
| 215 @"Only one cookie should be found in normal mode."); |
| 229 } | 216 } |
| 230 | 217 |
| 231 // Tests that a cookie set in incognito tab is only available in another | 218 // Tests that a cookie set in incognito tab is only available in another |
| 232 // incognito tab. They are not available in a normal tab. | 219 // incognito tab. They are not available in a normal tab. |
| 233 - (void)testSwitchToMain { | 220 - (void)testSwitchToMain { |
| 234 // Loads a page in normal tab and then switches to a new incognito tab. Sets | 221 // Loads a page in normal tab and then switches to a new incognito tab. Sets |
| 235 // cookie in incognito tab. | 222 // cookie in incognito tab. |
| 236 [ChromeEarlGrey | 223 [ChromeEarlGrey |
| 237 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 224 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 238 chrome_test_util::OpenNewIncognitoTab(); | 225 chrome_test_util::OpenNewIncognitoTab(); |
| 239 [ChromeEarlGrey | 226 [ChromeEarlGrey |
| 240 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; | 227 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoSetCookie)]; |
| 241 GREYAssertTrue(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 228 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 242 @"Failed to set incognito cookie in incognito mode. (1)"); | 229 GREYAssertEqualObjects(kIncognitoCookieValue, cookies[kIncognitoCookieName], |
| 230 @"Failed to set incognito cookie in incognito mode."); |
| 231 GREYAssertEqual(1U, cookies.count, |
| 232 @"Only one cookie should be found in incognito mode."); |
| 233 |
| 243 // Switches back to a normal tab and verifies that cookie set in incognito tab | 234 // Switches back to a normal tab and verifies that cookie set in incognito tab |
| 244 // is not available. | 235 // is not available. |
| 245 chrome_test_util::OpenNewTab(); | 236 chrome_test_util::OpenNewTab(); |
| 246 [ChromeEarlGrey | 237 [ChromeEarlGrey |
| 247 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 238 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 248 GREYAssertTrue(CheckNoCookieExists(), | 239 cookies = [ChromeEarlGrey cookies]; |
| 249 @"Incognito cookie should not be found in normal mode. (2)"); | 240 GREYAssertEqual(0U, cookies.count, |
| 241 @"Incognito cookie should not be found in normal mode."); |
| 242 |
| 250 // Returns back to Incognito tab and cookie is still there. | 243 // Returns back to Incognito tab and cookie is still there. |
| 251 chrome_test_util::OpenNewIncognitoTab(); | 244 chrome_test_util::OpenNewIncognitoTab(); |
| 252 [ChromeEarlGrey | 245 [ChromeEarlGrey |
| 253 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; | 246 loadURL:web::test::HttpServer::MakeUrl(kTestUrlIncognitoBrowsing)]; |
| 254 GREYAssertTrue(CheckCookieExists(kIncognitoCookieKey, kIncognitoCookieValue), | 247 cookies = [ChromeEarlGrey cookies]; |
| 255 @"Incognito cookie should be found in incognito mode. (3)"); | 248 GREYAssertEqualObjects( |
| 249 kIncognitoCookieValue, cookies[kIncognitoCookieName], |
| 250 @"Incognito cookie should be found in incognito mode."); |
| 251 GREYAssertEqual(1U, cookies.count, |
| 252 @"Only one cookie should be found in incognito mode."); |
| 256 } | 253 } |
| 257 | 254 |
| 258 // Tests that a cookie set in a normal tab can be found in another normal tab. | 255 // Tests that a cookie set in a normal tab can be found in another normal tab. |
| 259 - (void)testShareCookiesBetweenTabs { | 256 - (void)testShareCookiesBetweenTabs { |
| 260 // Loads page and sets cookie in first normal tab. | 257 // Loads page and sets cookie in first normal tab. |
| 261 [ChromeEarlGrey | 258 [ChromeEarlGrey |
| 262 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; | 259 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalSetCookie)]; |
| 263 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 260 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 264 @"Failed to set normal cookie in normal mode. (1)"); | 261 GREYAssertEqualObjects(kNormalCookieValue, cookies[kNormalCookieName], |
| 262 @"Failed to set normal cookie in normal mode."); |
| 263 GREYAssertEqual(1U, cookies.count, |
| 264 @"Only one cookie should be found in normal mode."); |
| 265 | 265 |
| 266 // Creates another normal tab and verifies that the cookie is also there. | 266 // Creates another normal tab and verifies that the cookie is also there. |
| 267 chrome_test_util::OpenNewTab(); | 267 chrome_test_util::OpenNewTab(); |
| 268 [ChromeEarlGrey | 268 [ChromeEarlGrey |
| 269 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; | 269 loadURL:web::test::HttpServer::MakeUrl(kTestUrlNormalBrowsing)]; |
| 270 GREYAssertTrue(CheckCookieExists(kNormalCookieKey, kNormalCookieValue), | 270 cookies = [ChromeEarlGrey cookies]; |
| 271 @"Normal cookie should still be found in normal mode. (2)"); | 271 GREYAssertEqualObjects( |
| 272 kNormalCookieValue, cookies[kNormalCookieName], |
| 273 @"Normal cookie should still be found in normal mode."); |
| 274 GREYAssertEqual(1U, cookies.count, |
| 275 @"Only one cookie should be found in normal mode."); |
| 272 } | 276 } |
| 273 | 277 |
| 274 @end | 278 @end |
| OLD | NEW |