Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: content/browser/dom_storage/dom_storage_browsertest.cc

Issue 9956117: DomStorageBrowserTest sanity check (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/in_process_webkit/dom_storage_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 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 "base/command_line.h" 5 #include "base/path_service.h"
6 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/test/base/in_process_browser_test.h"
7 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/tab_contents/tab_contents.h" 9 #include "content/browser/tab_contents/tab_contents.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_paths.h"
11 #include "content/test/layout_browsertest.h" 11 #include "net/base/net_util.h"
12 #include "webkit/dom_storage/dom_storage_types.h" 12 #include "webkit/dom_storage/dom_storage_types.h"
13 13
14 #ifdef ENABLE_NEW_DOM_STORAGE_BACKEND 14 // This browser test is aimed towards exercising the DomStorage system
15 // TODO(michaeln) Ensure they pass. 15 // from end-to-end.
16 #else 16 class DomStorageBrowserTest : public InProcessBrowserTest {
17 static const char* kRootFiles[] = { 17 public:
18 "clear.html", 18 DomStorageBrowserTest() {
19 // "complex-keys.html", // Output too big for a cookie. crbug.com/33472 19 EnableDOMAutomation();
20 // "complex-values.html", // crbug.com/33472 20 }
21 "quota.html", 21
22 "remove-item.html", 22 GURL GetTestURL(const char* name) {
23 "window-attributes-exist.html", 23 FilePath file_name = FilePath().AppendASCII(name);
24 NULL 24 FilePath dir;
25 PathService::Get(content::DIR_TEST_DATA, &dir);
26 return net::FilePathToFileURL(
27 dir.Append(FILE_PATH_LITERAL("dom_storage")).Append(file_name));
28 }
29
30 void SimpleTest(const GURL& test_url, bool incognito) {
31 // The test page will perform tests then navigate to either
32 // a #pass or #fail ref.
33 Browser* the_browser = incognito ? CreateIncognitoBrowser() : browser();
34 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
35 the_browser, test_url, 2);
36 std::string result = the_browser->GetSelectedWebContents()->GetURL().ref();
37 if (result != "pass") {
38 std::string js_result;
39 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
40 the_browser->GetSelectedWebContents()->GetRenderViewHost(), L"",
41 L"window.domAutomationController.send(getLog())", &js_result));
42 FAIL() << "Failed: " << js_result;
43 }
44 }
25 }; 45 };
26 46
27 static const char* kEventsFiles[] = { 47 static const bool kIncognito = true;
28 // "basic-body-attribute.html", // crbug.com/33472 48 static const bool kNotIncognito = false;
29 // "basic.html", // crbug.com/33472
30 // "basic-setattribute.html", // crbug.com/33472
31 "case-sensitive.html",
32 "documentURI.html",
33 NULL
34 };
35 49
36 static const char* kStorageFiles[] = { 50 IN_PROC_BROWSER_TEST_F(DomStorageBrowserTest, SanityCheck) {
37 "delete-removal.html", 51 SimpleTest(GetTestURL("sanity_check.html"), kNotIncognito);
38 "enumerate-storage.html",
39 "enumerate-with-length-and-key.html",
40 "index-get-and-set.html",
41 "simple-usage.html",
42 "string-conversion.html",
43 // "window-open.html", // TODO(jorlow): Fix
44 NULL
45 };
46
47 class DOMStorageTestBase : public InProcessBrowserLayoutTest {
48 protected:
49 DOMStorageTestBase(const FilePath& test_case_dir)
50 : InProcessBrowserLayoutTest(FilePath(), test_case_dir) {
51 }
52
53 virtual ~DOMStorageTestBase() {}
54
55 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
56 command_line->AppendSwitch(switches::kDisablePopupBlocking);
57 }
58
59 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
60 InProcessBrowserLayoutTest::SetUpInProcessBrowserTestFixture();
61 AddResourceForLayoutTest(
62 FilePath().AppendASCII("fast").AppendASCII("js"),
63 FilePath().AppendASCII("resources"));
64 }
65
66 // This is somewhat of a hack because we're running a real browser that
67 // actually persists the LocalStorage state vs. DRT and TestShell which don't.
68 // The correct fix is to fix the LayoutTests, but similar patches have been
69 // rejected in the past.
70 void ClearDOMStorage() {
71 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
72 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
73 L"localStorage.clear();sessionStorage.clear();"));
74 }
75
76 // Runs each test in an array of strings until it hits a NULL.
77 void RunTests(const char** files) {
78 while (*files) {
79 RunLayoutTest(*files);
80 ClearDOMStorage();
81 ++files;
82 }
83 }
84
85 FilePath test_dir_;
86 };
87
88 class DOMStorageTest : public DOMStorageTestBase {
89 public:
90 DOMStorageTest()
91 : DOMStorageTestBase(FilePath().AppendASCII("storage").
92 AppendASCII("domstorage")) {
93 }
94 virtual ~DOMStorageTest() {}
95 };
96
97
98 // http://crbug.com/113611
99 IN_PROC_BROWSER_TEST_F(DOMStorageTest, FAILS_RootLayoutTests) {
100 AddResourceForLayoutTest(FilePath(), FilePath().AppendASCII("script-tests"));
101 RunTests(kRootFiles);
102 } 52 }
103 53
104 class DOMStorageTestEvents : public DOMStorageTestBase { 54 IN_PROC_BROWSER_TEST_F(DomStorageBrowserTest, SanityCheckIncognito) {
105 public: 55 SimpleTest(GetTestURL("sanity_check.html"), kIncognito);
106 DOMStorageTestEvents()
107 : DOMStorageTestBase(FilePath().AppendASCII("storage").
108 AppendASCII("domstorage").
109 AppendASCII("events")) {
110 }
111 virtual ~DOMStorageTestEvents() {}
112 };
113
114 // Flakily fails on all platforms. http://crbug.com/102641
115 IN_PROC_BROWSER_TEST_F(DOMStorageTestEvents, DISABLED_EventLayoutTests) {
116 AddResourceForLayoutTest(
117 FilePath(),
118 FilePath().AppendASCII("storage").AppendASCII("domstorage").
119 AppendASCII("script-tests"));
120 RunTests(kEventsFiles);
121 } 56 }
122
123 class LocalStorageTest : public DOMStorageTestBase {
124 public:
125 LocalStorageTest()
126 : DOMStorageTestBase(FilePath().AppendASCII("storage").
127 AppendASCII("domstorage").
128 AppendASCII("localstorage")) {
129 }
130 virtual ~LocalStorageTest() {}
131 };
132
133 #if defined(OS_LINUX)
134 // http://crbug.com/104872
135 #define MAYBE_LocalStorageLayoutTests FAILS_LocalStorageLayoutTests
136 #else
137 #define MAYBE_LocalStorageLayoutTests LocalStorageLayoutTests
138 #endif
139
140 IN_PROC_BROWSER_TEST_F(LocalStorageTest, MAYBE_LocalStorageLayoutTests) {
141 RunTests(kStorageFiles);
142 }
143
144 class SessionStorageTest : public DOMStorageTestBase {
145 public:
146 SessionStorageTest()
147 : DOMStorageTestBase(FilePath().AppendASCII("storage").
148 AppendASCII("domstorage").
149 AppendASCII("sessionstorage")) {
150 }
151 virtual ~SessionStorageTest() {}
152 };
153
154 #if defined(OS_LINUX)
155 // http://crbug.com/104872
156 #define MAYBE_SessionStorageLayoutTests FAILS_SessionStorageLayoutTests
157 #else
158 #define MAYBE_SessionStorageLayoutTests SessionStorageLayoutTests
159 #endif
160
161 IN_PROC_BROWSER_TEST_F(SessionStorageTest, MAYBE_SessionStorageLayoutTests) {
162 RunTests(kStorageFiles);
163 }
164
165 #endif // ENABLE_NEW_DOM_STORAGE_BACKEND
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/in_process_webkit/dom_storage_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698