blob: 54da50a7272cac95b624d61373ade56a0a9eb491 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 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#include "base/path_service.h"
6#include "content/browser/web_contents/web_contents_impl.h"
Ben Murdochbb1529c2013-08-08 10:24:53 +01007#include "content/common/dom_storage/dom_storage_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +00008#include "content/public/common/content_paths.h"
9#include "content/public/test/browser_test_utils.h"
10#include "content/shell/shell.h"
11#include "content/test/content_browser_test.h"
12#include "content/test/content_browser_test_utils.h"
13#include "net/base/net_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014
15namespace content {
16
Ben Murdochbb1529c2013-08-08 10:24:53 +010017// This browser test is aimed towards exercising the DOMStorage system
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018// from end-to-end.
Ben Murdochbb1529c2013-08-08 10:24:53 +010019class DOMStorageBrowserTest : public ContentBrowserTest {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000020 public:
Ben Murdochbb1529c2013-08-08 10:24:53 +010021 DOMStorageBrowserTest() {}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000022
23 void SimpleTest(const GURL& test_url, bool incognito) {
24 // The test page will perform tests then navigate to either
25 // a #pass or #fail ref.
26 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell();
27 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2);
28 std::string result = the_browser->web_contents()->GetURL().ref();
29 if (result != "pass") {
30 std::string js_result;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000031 ASSERT_TRUE(ExecuteScriptAndExtractString(
32 the_browser->web_contents(),
33 "window.domAutomationController.send(getLog())",
34 &js_result));
Torne (Richard Coles)58218062012-11-14 11:43:16 +000035 FAIL() << "Failed: " << js_result;
36 }
37 }
38};
39
40static const bool kIncognito = true;
41static const bool kNotIncognito = false;
42
Ben Murdochbb1529c2013-08-08 10:24:53 +010043IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, SanityCheck) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000044 SimpleTest(GetTestUrl("dom_storage", "sanity_check.html"), kNotIncognito);
45}
46
Ben Murdochbb1529c2013-08-08 10:24:53 +010047IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, SanityCheckIncognito) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000048 SimpleTest(GetTestUrl("dom_storage", "sanity_check.html"), kIncognito);
49}
50
51} // namespace content