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