Chromium Code Reviews| Index: ios/web_view/test/web_view_incognito_inttest.mm |
| diff --git a/ios/web_view/test/web_view_incognito_inttest.mm b/ios/web_view/test/web_view_incognito_inttest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e67f6907ac92922f4b031356337512d87b55f4db |
| --- /dev/null |
| +++ b/ios/web_view/test/web_view_incognito_inttest.mm |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <ChromeWebView/ChromeWebView.h> |
| + |
| +#import "ios/web_view/test/web_view_test.h" |
| +#import "ios/web_view/test/web_view_test_util.h" |
| +#import "net/base/mac/url_conversions.h" |
| +#include "testing/gtest_mac.h" |
| +#include "url/gurl.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace ios_web_view { |
| + |
| +namespace { |
| + |
| +// Creates web view with incognito configuration and frame equal to screen |
| +// bounds. |
| +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 :)
|
| + return test::CreateWebView([CWVWebViewConfiguration incognitoConfiguration]); |
| +} |
| + |
| +} // namespace |
| + |
| +// Tests that browsing data (cookie and localStorage) does not leak between |
| +// incognito and non-incognito web views. |
| +typedef ios_web_view::WebViewTest WebViewIncognitoTest; |
| +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
|
| + // CWVWebView does not allow JavaScript execution if the page was not loaded. |
| + 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.
|
| + ASSERT_TRUE(test::LoadUrl(web_view_, net::NSURLWithGURL(url))); |
| + |
| + NSError* error = nil; |
| + test::EvaluateJavaScript(web_view_, @"localStorage.setItem('k', 'v');", |
| + &error); |
| + ASSERT_NSEQ(nil, error); |
| + test::EvaluateJavaScript(web_view_, @"document.cookie='n=v;'", &error); |
| + ASSERT_NSEQ(nil, error); |
| + |
| + // Create web view with the same configuration, otherwise browswing data may |
| + // not be shared immidiately. Make sure that new web view has browsing data |
| + // from the previous web view. |
| + 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
|
| + test::CreateWebView([web_view_ configuration]); |
| + ASSERT_TRUE(test::LoadUrl(non_incognito_web_view, net::NSURLWithGURL(url))); |
| + id localStorageValue = test::EvaluateJavaScript( |
| + non_incognito_web_view, @"localStorage.getItem('k');", &error); |
| + ASSERT_NSEQ(nil, error); |
| + ASSERT_NSEQ(@"v", localStorageValue); |
| + id cookie = test::EvaluateJavaScript(non_incognito_web_view, |
| + @"document.cookie", &error); |
| + ASSERT_NSEQ(nil, error); |
| + ASSERT_TRUE([cookie containsString:@"n=v"]); |
| + |
| + // Verify that incognito web view does not have browsing data from |
| + // non-incognito web view. |
| + CWVWebView* incognito_web_view = CreateIncognitoWebView(); |
| + ASSERT_TRUE(incognito_web_view); |
| + ASSERT_TRUE(test::LoadUrl(incognito_web_view, net::NSURLWithGURL(url))); |
| + localStorageValue = test::EvaluateJavaScript( |
| + incognito_web_view, @"localStorage.getItem('k');", &error); |
| + EXPECT_NSEQ(nil, error); |
| + ASSERT_NSEQ([NSNull null], localStorageValue); |
| + cookie = |
| + test::EvaluateJavaScript(incognito_web_view, @"document.cookie", &error); |
| + EXPECT_NSEQ(nil, error); |
| + ASSERT_NSEQ(@"", cookie); |
| +} |
| + |
| +} // namespace ios_web_view |