Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <ChromeWebView/ChromeWebView.h> | |
| 6 | |
| 7 #import "ios/web_view/test/web_view_test.h" | |
| 8 #import "ios/web_view/test/web_view_test_util.h" | |
| 9 #import "net/base/mac/url_conversions.h" | |
| 10 #include "testing/gtest_mac.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 14 #error "This file requires ARC support." | |
| 15 #endif | |
| 16 | |
| 17 namespace ios_web_view { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Creates web view with incognito configuration and frame equal to screen | |
| 22 // bounds. | |
| 23 CWVWebView* CreateIncognitoWebView() { | |
|
michaeldo
2017/06/16 20:04:27
Is this helper necessary? I'm ok with it, but I do
Eugene But (OOO till 7-30)
2017/06/20 00:36:32
Now it is called 2 times :)
| |
| 24 return test::CreateWebView([CWVWebViewConfiguration incognitoConfiguration]); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 // Tests that browsing data (cookie and localStorage) does not leak between | |
| 30 // incognito and non-incognito web views. | |
| 31 typedef ios_web_view::WebViewTest WebViewIncognitoTest; | |
| 32 TEST_F(WebViewIncognitoTest, BrowsingDataLeaking) { | |
|
Hiroshi Ichikawa
2017/06/16 08:28:20
It can be TODO, but do you want to check the oppos
Eugene But (OOO till 7-30)
2017/06/20 00:36:31
Added that test
| |
| 33 // CWVWebView does not allow JavaScript execution if the page was not loaded. | |
| 34 GURL url = GetUrlForPageWithHtmlBody("<html><html>"); | |
|
Hiroshi Ichikawa
2017/06/16 08:28:20
Do you mean <html></html>?
michaeldo
2017/06/16 20:04:27
There is no need for the html tag here, you can pa
Eugene But (OOO till 7-30)
2017/06/20 00:36:31
Done.
| |
| 35 ASSERT_TRUE(test::LoadUrl(web_view_, net::NSURLWithGURL(url))); | |
| 36 | |
| 37 NSError* error = nil; | |
| 38 test::EvaluateJavaScript(web_view_, @"localStorage.setItem('k', 'v');", | |
| 39 &error); | |
| 40 ASSERT_NSEQ(nil, error); | |
| 41 test::EvaluateJavaScript(web_view_, @"document.cookie='n=v;'", &error); | |
| 42 ASSERT_NSEQ(nil, error); | |
| 43 | |
| 44 // Create web view with the same configuration, otherwise browswing data may | |
| 45 // not be shared immidiately. Make sure that new web view has browsing data | |
| 46 // from the previous web view. | |
| 47 CWVWebView* non_incognito_web_view = | |
|
michaeldo
2017/06/16 20:04:27
Can this part be split into another test? Maybe "B
Eugene But (OOO till 7-30)
2017/06/20 00:36:32
This is more like a precondition, rather than actu
| |
| 48 test::CreateWebView([web_view_ configuration]); | |
| 49 ASSERT_TRUE(test::LoadUrl(non_incognito_web_view, net::NSURLWithGURL(url))); | |
| 50 id localStorageValue = test::EvaluateJavaScript( | |
| 51 non_incognito_web_view, @"localStorage.getItem('k');", &error); | |
| 52 ASSERT_NSEQ(nil, error); | |
| 53 ASSERT_NSEQ(@"v", localStorageValue); | |
| 54 id cookie = test::EvaluateJavaScript(non_incognito_web_view, | |
| 55 @"document.cookie", &error); | |
| 56 ASSERT_NSEQ(nil, error); | |
| 57 ASSERT_TRUE([cookie containsString:@"n=v"]); | |
| 58 | |
| 59 // Verify that incognito web view does not have browsing data from | |
| 60 // non-incognito web view. | |
| 61 CWVWebView* incognito_web_view = CreateIncognitoWebView(); | |
| 62 ASSERT_TRUE(incognito_web_view); | |
| 63 ASSERT_TRUE(test::LoadUrl(incognito_web_view, net::NSURLWithGURL(url))); | |
| 64 localStorageValue = test::EvaluateJavaScript( | |
| 65 incognito_web_view, @"localStorage.getItem('k');", &error); | |
| 66 EXPECT_NSEQ(nil, error); | |
| 67 ASSERT_NSEQ([NSNull null], localStorageValue); | |
| 68 cookie = | |
| 69 test::EvaluateJavaScript(incognito_web_view, @"document.cookie", &error); | |
| 70 EXPECT_NSEQ(nil, error); | |
| 71 ASSERT_NSEQ(@"", cookie); | |
| 72 } | |
| 73 | |
| 74 } // namespace ios_web_view | |
| OLD | NEW |