diff options
author | shreyasv <shreyasv@chromium.org> | 2015-11-15 11:41:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-15 19:42:08 +0000 |
commit | 02c0d6e43eeb3926f09819dfa6137315fe2a2381 (patch) | |
tree | b4b41b138b1b102eb038172ac88520191b62dfcf /ios/web/test | |
parent | 46dea497bd8762f25dca1c46c5e696d53fce24d2 (diff) | |
download | chromium_src-02c0d6e43eeb3926f09819dfa6137315fe2a2381.zip chromium_src-02c0d6e43eeb3926f09819dfa6137315fe2a2381.tar.gz chromium_src-02c0d6e43eeb3926f09819dfa6137315fe2a2381.tar.bz2 |
Added tests for separation of browsing data between BrowserStates
Since these tests require the bring-up of the HttpServer, added
a new target ios_web_inttests with equivalent test fixtures.
Moved http_server to this new suite and enabled the unittest
since
app transport security was disabled in
https://codereview.chromium.org/1306733002
Added tests for Cookies, LocalStorage.
Also factored out the StringResponseProvider from
http_server_inttest
BUG=520583, 516600
Review URL: https://codereview.chromium.org/1446523002
Cr-Commit-Position: refs/heads/master@{#359780}
Diffstat (limited to 'ios/web/test')
-rw-r--r-- | ios/web/test/web_int_test.h | 34 | ||||
-rw-r--r-- | ios/web/test/web_int_test.mm | 79 |
2 files changed, 113 insertions, 0 deletions
diff --git a/ios/web/test/web_int_test.h b/ios/web/test/web_int_test.h new file mode 100644 index 0000000..dc4e874 --- /dev/null +++ b/ios/web/test/web_int_test.h @@ -0,0 +1,34 @@ +// Copyright 2015 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. + +#ifndef IOS_WEB_TEST_WEB_INT_TEST_H_ +#define IOS_WEB_TEST_WEB_INT_TEST_H_ + +#import <WebKit/WebKit.h> + +#include "ios/web/test/web_test.h" + +namespace web { + +// A test fixture for integration tests that need to bring up the HttpServer. +class WebIntTest : public WebTest { + protected: + WebIntTest(); + ~WebIntTest() override; + + // WebTest methods. + void SetUp() override; + void TearDown() override; + + // Synchronously removes data from |data_store|. + // |websiteDataTypes| is from the constants defined in + // "WebKit/WKWebsiteDataRecord". + void RemoveWKWebViewCreatedData(WKWebsiteDataStore* data_store, + NSSet* websiteDataTypes); + +}; + +} // namespace web + +#endif // IOS_WEB_TEST_WEB_TEST_H_ diff --git a/ios/web/test/web_int_test.mm b/ios/web/test/web_int_test.mm new file mode 100644 index 0000000..cbfeaa7 --- /dev/null +++ b/ios/web/test/web_int_test.mm @@ -0,0 +1,79 @@ +// Copyright 2015 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 "ios/web/test/web_int_test.h" + +#include "base/ios/block_types.h" + +#include "base/test/ios/wait_util.h" +#import "ios/web/public/test/http_server.h" +#import "ios/web/public/web_view_creation_util.h" + +namespace web { + +WebIntTest::WebIntTest() {} +WebIntTest::~WebIntTest() {} + +void WebIntTest::SetUp() { + WebTest::SetUp(); + + web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); + ASSERT_FALSE(server.IsRunning()); + server.StartOrDie(); + + + if (IsWKWebViewSupported()) { + RemoveWKWebViewCreatedData([WKWebsiteDataStore defaultDataStore], + [WKWebsiteDataStore allWebsiteDataTypes]); + } +} + +void WebIntTest::TearDown() { + if (IsWKWebViewSupported()) { + RemoveWKWebViewCreatedData([WKWebsiteDataStore defaultDataStore], + [WKWebsiteDataStore allWebsiteDataTypes]); + } + + web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); + server.Stop(); + EXPECT_FALSE(server.IsRunning()); + + WebTest::TearDown(); +} + +void WebIntTest::RemoveWKWebViewCreatedData(WKWebsiteDataStore* data_store, + NSSet* websiteDataTypes) { + __block bool data_removed = false; + + ProceduralBlock remove_data = ^{ + [data_store removeDataOfTypes:websiteDataTypes + modifiedSince:[NSDate distantPast] + completionHandler:^{ + data_removed = true; + }]; + }; + + if ([websiteDataTypes containsObject:WKWebsiteDataTypeCookies]) { + // TODO(crbug.com/554225): This approach of creating a WKWebView and + // executing JS to clear cookies is a workaround for + // https://bugs.webkit.org/show_bug.cgi?id=149078. + // Remove this, when that bug is fixed. The |markerWKWebView| will be + // released when cookies have been cleared. + WKWebView* marker_web_view = + web::CreateWKWebView(CGRectZero, GetBrowserState()); + [marker_web_view evaluateJavaScript:@"" + completionHandler:^(id, NSError*) { + [marker_web_view release]; + remove_data(); + }]; + } else { + remove_data(); + } + + base::test::ios::WaitUntilCondition(^bool { + return data_removed; + }); +} + +} // namespace web |