diff options
-rw-r--r-- | chrome/test/data/workers/multi_worker.html | 52 | ||||
-rw-r--r-- | chrome/test/data/workers/single_worker.html | 25 | ||||
-rw-r--r-- | chrome/test/data/workers/worker_common.js | 11 | ||||
-rw-r--r-- | chrome/test/data/workers/worker_utils.js | 18 | ||||
-rw-r--r-- | chrome/test/ui/ui_tests.vcproj | 8 | ||||
-rw-r--r-- | chrome/worker/worker_uitest.cc | 39 |
6 files changed, 153 insertions, 0 deletions
diff --git a/chrome/test/data/workers/multi_worker.html b/chrome/test/data/workers/multi_worker.html new file mode 100644 index 0000000..b0ef8cc --- /dev/null +++ b/chrome/test/data/workers/multi_worker.html @@ -0,0 +1,52 @@ +<html> + +<head> +<title>Multi-Worker Test</title> + +<script src="worker_utils.js"></script> + +<script> + +var expected_total = 0; +var actual_total = 0; +var completed_worker_count = 0; +var total_workers = 4; + +function createWorker(base) { + var worker = new Worker("worker_common.js"); + for (var i = 0; i < 100; i++) { + worker.postMessage("eval " + base + "+" + i); + expected_total += base + i; + } + worker.postMessage("ping"); + worker.onmessage = function(evt) { + if (evt.data == "pong") { + completed_worker_count++; + if (completed_worker_count == total_workers) { + if (expected_total == actual_total) + onSuccess(); + else + onFailure(); + } + } else { + try { + actual_total += parseInt(evt.data); + } catch (ex) { + onFailure(); + } + } + } + return worker; +} + +for (var i = 0; i < total_workers; ++i) { + var worker = createWorker(100 + i); +} + +</script> +</head> + +<body> +<div id=statusPanel></div> +</body> +</html> diff --git a/chrome/test/data/workers/single_worker.html b/chrome/test/data/workers/single_worker.html new file mode 100644 index 0000000..d5b1962 --- /dev/null +++ b/chrome/test/data/workers/single_worker.html @@ -0,0 +1,25 @@ +<html> + +<head> +<title>Single Worker Test</title> + +<script src="worker_utils.js"></script> + +<script> + +var worker = new Worker("worker_common.js"); +worker.postMessage("ping"); +worker.onmessage = function(evt) { + if (evt.data == "pong") + onSuccess(); + else + onFailure(); +} + +</script> +</head> + +<body> +<div id=statusPanel></div> +</body> +</html> diff --git a/chrome/test/data/workers/worker_common.js b/chrome/test/data/workers/worker_common.js new file mode 100644 index 0000000..583c6a5 --- /dev/null +++ b/chrome/test/data/workers/worker_common.js @@ -0,0 +1,11 @@ +onmessage = function(evt) { + if (evt.data == "ping") + postMessage("pong"); + else if (/eval.+/.test(evt.data)) { + try { + postMessage(eval(evt.data.substr(5))); + } catch (ex) { + postMessage(ex); + } + } +} diff --git a/chrome/test/data/workers/worker_utils.js b/chrome/test/data/workers/worker_utils.js new file mode 100644 index 0000000..03c84631 --- /dev/null +++ b/chrome/test/data/workers/worker_utils.js @@ -0,0 +1,18 @@ +function onSuccess() +{ + setTimeout(onFinished, 0, "OK"); +} + +function onFailure() { + setTimeout(onFinished, 0, "FAIL"); +} + +function onFinished(result) { + var statusPanel = document.getElementById("statusPanel"); + if (statusPanel) { + statusPanel.innerHTML = result; + } + + var cookie = "status=" + result + "; path=/"; + document.cookie = cookie; +}
\ No newline at end of file diff --git a/chrome/test/ui/ui_tests.vcproj b/chrome/test/ui/ui_tests.vcproj index e50ff06..c959806 100644 --- a/chrome/test/ui/ui_tests.vcproj +++ b/chrome/test/ui/ui_tests.vcproj @@ -606,6 +606,14 @@ > </File> </Filter> + <Filter + Name="TestWorker" + > + <File + RelativePath="..\..\worker\worker_uitest.cc" + > + </File> + </Filter> </Files> <Globals> </Globals> diff --git a/chrome/worker/worker_uitest.cc b/chrome/worker/worker_uitest.cc new file mode 100644 index 0000000..6297cb3 --- /dev/null +++ b/chrome/worker/worker_uitest.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2009 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. + +#include "chrome/common/chrome_switches.h" +#include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/ui/ui_test.h" + +const char kTestCompleteCookie[] = "status"; +const char kTestCompleteSuccess[] = "OK"; +const int kTestIntervalMs = 250; +const int kTestWaitTimeoutMs = 10 * 1000; + +class WorkerTest : public UITest { + protected: + WorkerTest() : UITest() { + launch_arguments_.AppendSwitch(switches::kEnableWebWorkers); + } + + void RunTest(const std::wstring& test_case) { + scoped_ptr<TabProxy> tab(GetActiveTab()); + + GURL url = GetTestUrl(L"workers", test_case); + ASSERT_TRUE(tab->NavigateToURL(url)); + + std::string value = WaitUntilCookieNonEmpty(tab.get(), url, + kTestCompleteCookie, kTestIntervalMs, kTestWaitTimeoutMs); + ASSERT_STREQ(kTestCompleteSuccess, value.c_str()); + } +}; + +TEST_F(WorkerTest, SingleWorker) { + RunTest(L"single_worker.html"); +} + +TEST_F(WorkerTest, MultipleWorkers) { + RunTest(L"multi_worker.html"); +} + |