diff options
author | jabdelmalek@google.com <jabdelmalek@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 16:44:11 +0000 |
---|---|---|
committer | jabdelmalek@google.com <jabdelmalek@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 16:44:11 +0000 |
commit | bedf8749411d079d41d62263ed434d86dab708bd (patch) | |
tree | 586ef192471003427019b65b46a69d0bf4f06653 /ppapi/tests | |
parent | 7b5635c1046e7d6f41521e8ff77b7ff1152cf48b (diff) | |
download | chromium_src-bedf8749411d079d41d62263ed434d86dab708bd.zip chromium_src-bedf8749411d079d41d62263ed434d86dab708bd.tar.gz chromium_src-bedf8749411d079d41d62263ed434d86dab708bd.tar.bz2 |
Use a random port for WebSocket tests. In browser_tests the websocket server might run simultaneously when the sharding supervisor is used. In practice I haven't seen a try run that fails from this because the sharding_supervisor reruns failed tests serially, but probably good to fix this.
BUG=118460
Review URL: https://chromiumcodereview.appspot.com/9693066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_case.html | 13 | ||||
-rw-r--r-- | ppapi/tests/test_websocket.cc | 66 | ||||
-rw-r--r-- | ppapi/tests/test_websocket.h | 1 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.cc | 14 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.h | 5 |
5 files changed, 62 insertions, 37 deletions
diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html index f5c046e..3a72366 100644 --- a/ppapi/tests/test_case.html +++ b/ppapi/tests/test_case.html @@ -28,10 +28,14 @@ function AppendFrame(testcase, i) { var frame = document.createElement("IFRAME"); var mode = ExtractSearchParameter("mode"); + var websocket_port = ExtractSearchParameter("websocket_port"); + var src = "?testcase=" + testcase; if (mode == "nacl") - frame.setAttribute("src", "?testcase=" + testcase + "&mode=nacl"); - else - frame.setAttribute("src", "?testcase=" + testcase); + src += "&mode=nacl"; + if (websocket_port != "") + src += "&websocket_port=" + websocket_port; + frame.setAttribute("src", src); + frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")"); p.appendChild(frame); @@ -167,6 +171,9 @@ onload = function() { obj.setAttribute("id", "plugin"); obj.setAttribute("testcase", testcase); obj.setAttribute("protocol", window.location.protocol); + var websocket_port = ExtractSearchParameter("websocket_port"); + if (websocket_port != "") + obj.setAttribute("websocket_port", websocket_port); var container = document.getElementById("container"); container.addEventListener("message", handleTestingMessage, true); // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc index d4a9fc5..1992e3e 100644 --- a/ppapi/tests/test_websocket.cc +++ b/ppapi/tests/test_websocket.cc @@ -4,6 +4,7 @@ #include "ppapi/tests/test_websocket.h" +#include <stdio.h> #include <string.h> #include <algorithm> #include <string> @@ -31,14 +32,12 @@ // These servers are provided by pywebsocket server side handlers in // LayoutTests/http/tests/websocket/tests/hybi/*_wsh. // pywebsocket server itself is launched in ppapi_ui_test.cc. -const char kEchoServerURL[] = - "ws://localhost:8880/websocket/tests/hybi/echo-with-no-extension"; +const char kEchoServerURL[] = "websocket/tests/hybi/echo-with-no-extension"; -const char kCloseServerURL[] = - "ws://localhost:8880/websocket/tests/hybi/close"; +const char kCloseServerURL[] = "websocket/tests/hybi/close"; const char kProtocolTestServerURL[] = - "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; + "websocket/tests/hybi/protocol-test?protocol="; const char* const kInvalidURLs[] = { "http://www.google.com/invalid_scheme", @@ -213,6 +212,19 @@ void TestWebSocket::RunTests(const std::string& filter) { RUN_TEST_WITH_REFERENCE_CHECK(UtilityBufferedAmount, filter); } +std::string TestWebSocket::GetFullURL(const char* url) { + std::string rv = "ws://localhost"; + // Some WebSocket tests don't start the server so there'll be no port. + if (instance_->websocket_port() != -1) { + char buffer[10]; + sprintf(buffer, ":%d", instance_->websocket_port()); + rv += std::string(buffer); + } + rv += "/"; + rv += url; + return rv; +} + PP_Var TestWebSocket::CreateVarString(const std::string& string) { return var_interface_->VarFromUtf8(string.c_str(), string.size()); } @@ -365,7 +377,7 @@ std::string TestWebSocket::TestInvalidConnect() { } std::string TestWebSocket::TestProtocols() { - PP_Var url = CreateVarString(kEchoServerURL); + PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); PP_Var bad_protocols[] = { CreateVarString("x-test"), CreateVarString("x-test") @@ -421,7 +433,7 @@ std::string TestWebSocket::TestGetURL() { std::string TestWebSocket::TestValidConnect() { int32_t result; - PP_Resource ws = Connect(kEchoServerURL, &result, ""); + PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, result); PP_Var extensions = websocket_interface_->GetExtensions(ws); @@ -444,7 +456,7 @@ std::string TestWebSocket::TestInvalidClose() { core_interface_->ReleaseResource(ws); // Close with bad arguments. - ws = Connect(kEchoServerURL, &result, ""); + ws = Connect(GetFullURL(kEchoServerURL), &result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, result); result = websocket_interface_->Close(ws, 1U, reason, @@ -459,14 +471,14 @@ std::string TestWebSocket::TestInvalidClose() { std::string TestWebSocket::TestValidClose() { PP_Var reason = CreateVarString("close for test"); - PP_Var url = CreateVarString(kEchoServerURL); + PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); PP_Var protocols[] = { PP_MakeUndefined() }; TestCompletionCallback callback(instance_->pp_instance()); TestCompletionCallback another_callback(instance_->pp_instance()); // Close. int32_t result; - PP_Resource ws = Connect(kEchoServerURL, &result, ""); + PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, result); result = websocket_interface_->Close(ws, @@ -498,7 +510,7 @@ std::string TestWebSocket::TestValidClose() { // Close in closing. // The first close will be done successfully, then the second one failed with // with PP_ERROR_INPROGRESS immediately. - ws = Connect(kEchoServerURL, &result, ""); + ws = Connect(GetFullURL(kEchoServerURL), &result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, result); result = websocket_interface_->Close(ws, @@ -515,7 +527,7 @@ std::string TestWebSocket::TestValidClose() { core_interface_->ReleaseResource(ws); // Close with ongoing receive message. - ws = Connect(kEchoServerURL, &result, ""); + ws = Connect(GetFullURL(kEchoServerURL), &result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, result); PP_Var receive_message_var; @@ -546,7 +558,7 @@ std::string TestWebSocket::TestGetProtocol() { NULL }; for (int i = 0; expected_protocols[i]; ++i) { - std::string url(kProtocolTestServerURL); + std::string url(GetFullURL(kProtocolTestServerURL)); url += expected_protocols[i]; int32_t result; PP_Resource ws = Connect(url.c_str(), &result, expected_protocols[i]); @@ -566,7 +578,7 @@ std::string TestWebSocket::TestGetProtocol() { std::string TestWebSocket::TestTextSendReceive() { // Connect to test echo server. int32_t connect_result; - PP_Resource ws = Connect(kEchoServerURL, &connect_result, ""); + PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, connect_result); @@ -596,7 +608,7 @@ std::string TestWebSocket::TestTextSendReceive() { std::string TestWebSocket::TestBinarySendReceive() { // Connect to test echo server. int32_t connect_result; - PP_Resource ws = Connect(kEchoServerURL, &connect_result, ""); + PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, connect_result); @@ -628,7 +640,7 @@ std::string TestWebSocket::TestBinarySendReceive() { std::string TestWebSocket::TestBufferedAmount() { // Connect to test echo server. int32_t connect_result; - PP_Resource ws = Connect(kEchoServerURL, &connect_result, ""); + PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &connect_result, ""); ASSERT_TRUE(ws); ASSERT_EQ(PP_OK, connect_result); @@ -706,7 +718,7 @@ std::string TestWebSocket::TestCcInterfaces() { // Check communication interfaces (connect, send, receive, and close). TestCompletionCallback connect_callback(instance_->pp_instance()); - int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, + int32_t result = ws.Connect(pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, connect_callback); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); result = connect_callback.WaitForResult(); @@ -755,7 +767,7 @@ std::string TestWebSocket::TestCcInterfaces() { ASSERT_EQ(true, ws.GetCloseWasClean()); ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); - ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); + ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), GetFullURL(kCloseServerURL).c_str())); PASS(); } @@ -791,7 +803,7 @@ std::string TestWebSocket::TestUtilityProtocols() { { TestWebSocketAPI websocket(instance_); int32_t result = websocket.Connect( - pp::Var(std::string(kEchoServerURL)), bad_protocols, 2U); + pp::Var(GetFullURL(kEchoServerURL)), bad_protocols, 2U); ASSERT_EQ(PP_ERROR_BADARGUMENT, result); ASSERT_EQ(0U, websocket.GetSeenEvents().size()); } @@ -799,7 +811,7 @@ std::string TestWebSocket::TestUtilityProtocols() { { TestWebSocketAPI websocket(instance_); int32_t result = websocket.Connect( - pp::Var(std::string(kEchoServerURL)), good_protocols, 2U); + pp::Var(GetFullURL(kEchoServerURL)), good_protocols, 2U); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); @@ -835,7 +847,7 @@ std::string TestWebSocket::TestUtilityValidConnect() { const pp::Var protocols[] = { pp::Var() }; TestWebSocketAPI websocket(instance_); int32_t result = websocket.Connect( - pp::Var(std::string(kEchoServerURL)), protocols, 0U); + pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); @@ -861,7 +873,7 @@ std::string TestWebSocket::TestUtilityInvalidClose() { // Close with bad arguments. { TestWebSocketAPI websocket(instance_); - int32_t result = websocket.Connect(pp::Var(std::string(kEchoServerURL)), + int32_t result = websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), NULL, 0); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); @@ -877,7 +889,7 @@ std::string TestWebSocket::TestUtilityInvalidClose() { std::string TestWebSocket::TestUtilityValidClose() { std::string reason("close for test"); - pp::Var url = pp::Var(std::string(kCloseServerURL)); + pp::Var url = pp::Var(GetFullURL(kCloseServerURL)); // Close. { @@ -948,7 +960,7 @@ std::string TestWebSocket::TestUtilityValidClose() { std::string TestWebSocket::TestUtilityGetProtocol() { const std::string protocol("x-chat"); const pp::Var protocols[] = { pp::Var(protocol) }; - std::string url(kProtocolTestServerURL); + std::string url(GetFullURL(kProtocolTestServerURL)); url += protocol; TestWebSocketAPI websocket(instance_); int32_t result = websocket.Connect(pp::Var(url), protocols, 1U); @@ -973,7 +985,7 @@ std::string TestWebSocket::TestUtilityTextSendReceive() { const pp::Var protocols[] = { pp::Var() }; TestWebSocketAPI websocket(instance_); int32_t result = - websocket.Connect(pp::Var(std::string(kEchoServerURL)), protocols, 0U); + websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); @@ -1007,7 +1019,7 @@ std::string TestWebSocket::TestUtilityBinarySendReceive() { const pp::Var protocols[] = { pp::Var() }; TestWebSocketAPI websocket(instance_); int32_t result = - websocket.Connect(pp::Var(std::string(kEchoServerURL)), protocols, 0U); + websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); @@ -1039,7 +1051,7 @@ std::string TestWebSocket::TestUtilityBufferedAmount() { const pp::Var protocols[] = { pp::Var() }; TestWebSocketAPI websocket(instance_); int32_t result = - websocket.Connect(pp::Var(std::string(kEchoServerURL)), protocols, 0U); + websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); websocket.WaitForConnected(); diff --git a/ppapi/tests/test_websocket.h b/ppapi/tests/test_websocket.h index 027b3be..3b8f38d 100644 --- a/ppapi/tests/test_websocket.h +++ b/ppapi/tests/test_websocket.h @@ -22,6 +22,7 @@ class TestWebSocket : public TestCase { virtual bool Init(); virtual void RunTests(const std::string& filter); + std::string GetFullURL(const char* url); PP_Var CreateVarString(const std::string& string); PP_Var CreateVarBinary(const std::vector<uint8_t>& binary); void ReleaseVar(const PP_Var& var); diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc index 43cc000..4202181 100644 --- a/ppapi/tests/testing_instance.cc +++ b/ppapi/tests/testing_instance.cc @@ -30,7 +30,8 @@ TestingInstance::TestingInstance(PP_Instance instance) #endif current_case_(NULL), executed_tests_(false), - nacl_mode_(false) { + nacl_mode_(false), + websocket_port_(-1) { callback_factory_.Initialize(this); } @@ -46,9 +47,11 @@ bool TestingInstance::Init(uint32_t argc, if (std::strcmp(argn[i], "mode") == 0) { if (std::strcmp(argv[i], "nacl") == 0) nacl_mode_ = true; - } - else if (std::strcmp(argn[i], "protocol") == 0) + } else if (std::strcmp(argn[i], "protocol") == 0) { protocol_ = argv[i]; + } else if (std::strcmp(argn[i], "websocket_port") == 0) { + websocket_port_ = atoi(argv[i]); + } } // Create the proper test case from the argument. for (uint32_t i = 0; i < argc; i++) { @@ -172,10 +175,7 @@ void TestingInstance::ExecuteTests(int32_t unused) { } TestCase* TestingInstance::CaseForTestName(const std::string& name) { - std::string case_name = name; - if (case_name.find("SLOW_") == 0) - case_name = case_name.substr(5); - case_name = case_name.substr(0, case_name.find_first_of('_')); + std::string case_name = name.substr(0, name.find_first_of('_')); TestCaseFactory* iter = TestCaseFactory::head_; while (iter != NULL) { if (case_name == iter->name_) diff --git a/ppapi/tests/testing_instance.h b/ppapi/tests/testing_instance.h index 55c7e3d..8dadb20 100644 --- a/ppapi/tests/testing_instance.h +++ b/ppapi/tests/testing_instance.h @@ -82,6 +82,8 @@ pp::InstancePrivate { return protocol_; } + int websocket_port() { return websocket_port_; } + // Posts a message to the test page to eval() the script. void EvalScript(const std::string& script); @@ -137,6 +139,9 @@ pp::InstancePrivate { // String representing the protocol. Used for detecting whether we're running // with http. std::string protocol_; + + // WebSocket port. + int websocket_port_; }; #endif // PPAPI_TESTS_TESTING_INSTANCE_H_ |