summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xchrome/browser/extensions/extension_websocket_apitest.cc17
-rwxr-xr-xchrome/chrome_tests.gypi1
-rwxr-xr-xchrome/test/data/extensions/api_test/websocket/manifest.json6
-rwxr-xr-xchrome/test/data/extensions/api_test/websocket/test.html34
-rw-r--r--chrome/test/ui/ui_test.cc41
-rw-r--r--chrome/test/ui/ui_test.h5
-rw-r--r--chrome/test/ui_test_utils.cc56
-rw-r--r--chrome/test/ui_test_utils.h40
-rw-r--r--chrome/worker/worker_uitest.cc5
9 files changed, 157 insertions, 48 deletions
diff --git a/chrome/browser/extensions/extension_websocket_apitest.cc b/chrome/browser/extensions/extension_websocket_apitest.cc
new file mode 100755
index 0000000..3d2b6a5
--- /dev/null
+++ b/chrome/browser/extensions/extension_websocket_apitest.cc
@@ -0,0 +1,17 @@
+// Copyright (c) 2010 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/browser/extensions/extension_apitest.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/ui_test_utils.h"
+#include "net/base/mock_host_resolver.h"
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebSocket) {
+ FilePath websocket_root_dir;
+ PathService::Get(chrome::DIR_TEST_DATA, &websocket_root_dir);
+ websocket_root_dir = websocket_root_dir.AppendASCII("layout_tests")
+ .AppendASCII("LayoutTests");
+ ui_test_utils::TestWebSocketServer server(websocket_root_dir);
+ ASSERT_TRUE(RunExtensionTest("websocket")) << message_;
+}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 0390631..8d69447 100755
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1164,6 +1164,7 @@
'browser/extensions/extension_tabs_apitest.cc',
'browser/extensions/extension_toolbar_model_unittest.cc',
'browser/extensions/extension_toolstrip_apitest.cc',
+ 'browser/extensions/extension_websocket_apitest.cc',
'browser/extensions/fragment_navigation_apitest.cc',
'browser/extensions/incognito_noscript_apitest.cc',
'browser/extensions/isolated_world_apitest.cc',
diff --git a/chrome/test/data/extensions/api_test/websocket/manifest.json b/chrome/test/data/extensions/api_test/websocket/manifest.json
new file mode 100755
index 0000000..03b3ee7
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/websocket/manifest.json
@@ -0,0 +1,6 @@
+{
+ "name": "websockets tests",
+ "version": "0.1",
+ "description": "Sanity check that WebSockets work for extensions. The majority of this is implemented (and tested) in WebKit, but we have a sanity test here just to make sure the integration with Chromium keeps working.",
+ "background_page": "test.html"
+}
diff --git a/chrome/test/data/extensions/api_test/websocket/test.html b/chrome/test/data/extensions/api_test/websocket/test.html
new file mode 100755
index 0000000..5793929
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/websocket/test.html
@@ -0,0 +1,34 @@
+<script>
+chrome.test.runTests([
+ function echoTest() {
+ var ws = new WebSocket(
+ "ws://localhost:8880/websocket/tests/workers/resources/echo");
+ var MESSAGE_A = "message a";
+ var MESSAGE_B = "message b";
+
+ ws.onopen = function() {
+ chrome.test.log("websocket opened.");
+ ws.send(MESSAGE_A);
+ };
+
+ ws.onclose = function() {
+ chrome.test.log("websocket closed.");
+ }
+
+ ws.onmessage = function(messageEvent) {
+ chrome.test.log("message received: " + messageEvent.data);
+ chrome.test.assertEq(MESSAGE_A, messageEvent.data);
+
+ ws.onmessage = function(messageEvent) {
+ chrome.test.log("message received: " + messageEvent.data);
+ chrome.test.assertEq(MESSAGE_B, messageEvent.data);
+ ws.close();
+
+ chrome.test.succeed();
+ };
+
+ ws.send(MESSAGE_B);
+ };
+ }
+]);
+</script>
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 7f8bdb8..20c197d 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -273,25 +273,6 @@ static CommandLine* CreateHttpServerCommandLine() {
return cmd_line;
}
-static CommandLine* CreateWebSocketServerCommandLine() {
- FilePath src_path;
- // Get to 'src' dir.
- PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
-
- FilePath script_path(src_path);
- script_path = script_path.AppendASCII("webkit");
- script_path = script_path.AppendASCII("tools");
- script_path = script_path.AppendASCII("layout_tests");
- script_path = script_path.AppendASCII("webkitpy");
- script_path = script_path.AppendASCII("layout_tests");
- script_path = script_path.AppendASCII("layout_package");
- script_path = script_path.AppendASCII("websocket_server.py");
-
- CommandLine* cmd_line = CreatePythonCommandLine();
- cmd_line->AppendLooseValue(script_path.ToWStringHack());
- return cmd_line;
-}
-
static void RunCommand(const CommandLine& cmd_line) {
#if defined(OS_WIN)
// For Win32, use this 'version' of base::LaunchApp() with bInheritHandles
@@ -351,28 +332,6 @@ void UITestBase::StopHttpServer() {
RunCommand(*cmd_line.get());
}
-void UITestBase::StartWebSocketServer(const FilePath& root_directory) {
- scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
- ASSERT_TRUE(cmd_line.get());
- cmd_line->AppendSwitchWithValue("server", "start");
- cmd_line->AppendSwitch("register_cygwin");
- cmd_line->AppendSwitchWithValue("root", root_directory.ToWStringHack());
-
- websocket_pid_file_ = user_data_dir_.AppendASCII("websocket.pid");
- cmd_line->AppendSwitchWithValue("pidfile",
- websocket_pid_file_.ToWStringHack());
- RunCommand(*cmd_line.get());
-}
-
-void UITestBase::StopWebSocketServer() {
- scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
- ASSERT_TRUE(cmd_line.get());
- cmd_line->AppendSwitchWithValue("server", "stop");
- cmd_line->AppendSwitchWithValue("pidfile",
- websocket_pid_file_.ToWStringHack());
- RunCommand(*cmd_line.get());
-}
-
void UITestBase::LaunchBrowser(const CommandLine& arguments,
bool clear_profile) {
#if defined(OS_POSIX)
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index 6dc2a5a..a18b14b 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -484,11 +484,6 @@ class UITestBase {
const std::wstring& port);
void StopHttpServer();
- // Synchronously launches local websocket server used to run LayoutTests.
- void StartWebSocketServer(const FilePath& root_directory);
-
- void StopWebSocketServer();
-
// Prints IO performance data for use by perf graphs.
void PrintIOPerfInfo(const char* test_name);
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index 6eac7fa..d1cd7d3 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -29,6 +29,7 @@
#endif
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
namespace ui_test_utils {
@@ -572,4 +573,59 @@ void TimedMessageLoopRunner::QuitAfter(int ms) {
loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, ms);
}
+TestWebSocketServer::TestWebSocketServer(const FilePath& root_directory) {
+ scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
+ cmd_line->AppendSwitchWithValue("server", "start");
+ cmd_line->AppendSwitch("register_cygwin");
+ cmd_line->AppendSwitchWithValue("root", root_directory.ToWStringHack());
+ temp_dir_.CreateUniqueTempDir();
+ websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid");
+ cmd_line->AppendSwitchWithValue("pidfile",
+ websocket_pid_file_.ToWStringHack());
+ base::LaunchApp(*cmd_line.get(), true, false, NULL);
+}
+
+CommandLine* TestWebSocketServer::CreatePythonCommandLine() {
+#if defined(OS_WIN)
+ // Get path to python interpreter
+ FilePath python_runtime;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_runtime))
+ return NULL;
+ python_runtime = python_runtime
+ .Append(FILE_PATH_LITERAL("third_party"))
+ .Append(FILE_PATH_LITERAL("python_24"))
+ .Append(FILE_PATH_LITERAL("python.exe"));
+ return new CommandLine(python_runtime);
+#elif defined(OS_POSIX)
+ return new CommandLine(FilePath("python"));
+#endif
+}
+
+CommandLine* TestWebSocketServer::CreateWebSocketServerCommandLine() {
+ FilePath src_path;
+ // Get to 'src' dir.
+ PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
+
+ FilePath script_path(src_path);
+ script_path = script_path.AppendASCII("webkit");
+ script_path = script_path.AppendASCII("tools");
+ script_path = script_path.AppendASCII("layout_tests");
+ script_path = script_path.AppendASCII("webkitpy");
+ script_path = script_path.AppendASCII("layout_tests");
+ script_path = script_path.AppendASCII("layout_package");
+ script_path = script_path.AppendASCII("websocket_server.py");
+
+ CommandLine* cmd_line = CreatePythonCommandLine();
+ cmd_line->AppendLooseValue(script_path.ToWStringHack());
+ return cmd_line;
+}
+
+TestWebSocketServer::~TestWebSocketServer() {
+ scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
+ cmd_line->AppendSwitchWithValue("server", "stop");
+ cmd_line->AppendSwitchWithValue("pidfile",
+ websocket_pid_file_.ToWStringHack());
+ base::LaunchApp(*cmd_line.get(), true, false, NULL);
+}
+
} // namespace ui_test_utils
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index d59d6c1..2e5d52a 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/scoped_temp_dir.h"
#include "base/string16.h"
#include "chrome/browser/view_ids.h"
#include "chrome/common/notification_observer.h"
@@ -15,12 +16,15 @@
class AppModalDialog;
class Browser;
+class CommandLine;
class DownloadManager;
+class FilePath;
class GURL;
class MessageLoop;
class NavigationController;
class Profile;
class RenderViewHost;
+class ScopedTempDir;
class TabContents;
class Value;
@@ -178,6 +182,42 @@ class TimedMessageLoopRunner {
DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner);
};
+// This is a utility class for running a python websocket server
+// during tests. The server is started during the construction of the
+// object, and is stopped when the destructor is called. Note that
+// because of the underlying script that is used:
+//
+// webkit/tools/layout_tests/webkitpy/layout_tests/layout_package/
+// websocket_server.py
+//
+// Only *_wsh.py handlers found under "websocket/tests" from the
+// |root_directory| will be found and active while running the test
+// server.
+class TestWebSocketServer {
+ public:
+ // Creates and starts a python websocket server with |root_directory|.
+ explicit TestWebSocketServer(const FilePath& root_directory);
+
+ // Destroys and stops the server.
+ ~TestWebSocketServer();
+
+ private:
+ // Creates a CommandLine for invoking the python interpreter.
+ CommandLine* CreatePythonCommandLine();
+
+ // Creates a CommandLine for invoking the python websocker server.
+ CommandLine* CreateWebSocketServerCommandLine();
+
+ // A Scoped temporary directory for holding the python pid file.
+ ScopedTempDir temp_dir_;
+
+ // Used to close the same python interpreter when server falls out
+ // scope.
+ FilePath websocket_pid_file_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWebSocketServer);
+};
+
} // namespace ui_test_utils
#endif // CHROME_TEST_UI_TEST_UTILS_H_
diff --git a/chrome/worker/worker_uitest.cc b/chrome/worker/worker_uitest.cc
index b19ebd2..b36f9dd 100644
--- a/chrome/worker/worker_uitest.cc
+++ b/chrome/worker/worker_uitest.cc
@@ -9,6 +9,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_layout_test.h"
+#include "chrome/test/ui_test_utils.h"
#include "net/url_request/url_request_unittest.h"
static const char kTestCompleteCookie[] = "status";
@@ -378,10 +379,10 @@ TEST_F(WorkerTest, FLAKY_WorkerWebSocketLayoutTests) {
test_case_dir_ = test_case_dir_.AppendASCII("tests");
test_case_dir_ = test_case_dir_.AppendASCII("workers");
- StartWebSocketServer(temp_test_dir_.AppendASCII("LayoutTests"));
+ ui_test_utils::TestWebSocketServer websocket_server(
+ temp_test_dir_.AppendASCII("LayoutTests"));
for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
RunLayoutTest(kLayoutTestFiles[i], kWebSocketPort);
- StopWebSocketServer();
}
TEST_F(WorkerTest, WorkerXhrHttpLayoutTests) {