| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 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 <string> |
| 6 #include <vector> |
| 7 |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/test/webdriver/commands/implicit_wait_command.h" |
| 11 #include "chrome/test/webdriver/commands/response.h" |
| 12 #include "chrome/test/webdriver/error_codes.h" |
| 13 #include "chrome/test/webdriver/session.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace webdriver { |
| 17 |
| 18 namespace { |
| 19 |
| 20 void AssertIsAbleToInitialize(ImplicitWaitCommand* const command) { |
| 21 Response response; |
| 22 EXPECT_TRUE(command->Init(&response)); |
| 23 ASSERT_EQ(kSuccess, response.status()) << response.ToJSON(); |
| 24 } |
| 25 |
| 26 void AssertError(ErrorCode expected_status, |
| 27 const std::string& expected_message, |
| 28 ImplicitWaitCommand* const command) { |
| 29 Response response; |
| 30 command->ExecutePost(&response); |
| 31 ASSERT_EQ(expected_status, response.status()) << response.ToJSON(); |
| 32 |
| 33 const Value* value = response.value(); |
| 34 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); |
| 35 |
| 36 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); |
| 37 std::string actual_message; |
| 38 ASSERT_TRUE(dict->GetString("message", &actual_message)); |
| 39 ASSERT_EQ(expected_message, actual_message); |
| 40 } |
| 41 |
| 42 void AssertTimeoutSet(const Session& test_session, int expected_timeout, |
| 43 ImplicitWaitCommand* const command) { |
| 44 Response response; |
| 45 command->ExecutePost(&response); |
| 46 ASSERT_EQ(kSuccess, response.status()) << response.ToJSON(); |
| 47 ASSERT_EQ(expected_timeout, test_session.implicit_wait()); |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 TEST(ImplicitWaitCommandTest, SettingImplicitWaits) { |
| 53 Session test_session; |
| 54 ASSERT_EQ(0, test_session.implicit_wait()) << "Sanity check failed"; |
| 55 |
| 56 std::vector<std::string> path_segments; |
| 57 path_segments.push_back(""); |
| 58 path_segments.push_back("session"); |
| 59 path_segments.push_back(test_session.id()); |
| 60 path_segments.push_back("timeouts"); |
| 61 path_segments.push_back("implicitly_wait"); |
| 62 |
| 63 DictionaryValue* parameters = new DictionaryValue; // Owned by |command|. |
| 64 ImplicitWaitCommand command(path_segments, parameters); |
| 65 |
| 66 AssertIsAbleToInitialize(&command); |
| 67 |
| 68 AssertError(kBadRequest, "Request missing ms parameter", &command); |
| 69 |
| 70 parameters->Set("ms", Value::CreateNullValue()); |
| 71 AssertError(kBadRequest, "ms parameter is not a number", &command); |
| 72 |
| 73 parameters->SetString("ms", "apples"); |
| 74 AssertError(kBadRequest, "ms parameter is not a number", &command); |
| 75 |
| 76 parameters->SetInteger("ms", -1); |
| 77 AssertError(kBadRequest, "Wait must be non-negative: -1", &command); |
| 78 |
| 79 parameters->SetDouble("ms", -3.0); |
| 80 AssertError(kBadRequest, "Wait must be non-negative: -3", &command); |
| 81 |
| 82 parameters->SetInteger("ms", 1); |
| 83 AssertTimeoutSet(test_session, 1, &command); |
| 84 parameters->SetInteger("ms", 2.5); |
| 85 AssertTimeoutSet(test_session, 2, &command); |
| 86 parameters->SetInteger("ms", 0); |
| 87 AssertTimeoutSet(test_session, 0, &command); |
| 88 } |
| 89 |
| 90 } // namespace webdriver |
| 91 |
| OLD | NEW |