Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4873)

Unified Diff: chrome/test/chromedriver/session_commands_unittest.cc

Issue 19616008: [chromedriver] Allow commands to be async. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/session_commands.cc ('k') | chrome/test/chromedriver/session_map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/session_commands_unittest.cc
diff --git a/chrome/test/chromedriver/session_commands_unittest.cc b/chrome/test/chromedriver/session_commands_unittest.cc
index 33a748b3fbbb19f3c5282835b056d40758c0c7c1..1b6ef7b42e813ad231fdfa927dfc584ec2ac848b 100644
--- a/chrome/test/chromedriver/session_commands_unittest.cc
+++ b/chrome/test/chromedriver/session_commands_unittest.cc
@@ -8,114 +8,106 @@
#include "base/callback.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/threading/thread.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/stub_chrome.h"
-#include "chrome/test/chromedriver/fake_session_accessor.h"
+#include "chrome/test/chromedriver/commands.h"
#include "chrome/test/chromedriver/session.h"
#include "chrome/test/chromedriver/session_commands.h"
-#include "chrome/test/chromedriver/session_map.h"
#include "testing/gtest/include/gtest/gtest.h"
+TEST(SessionCommandTest, FileUpload) {
+ Session session("id");
+ base::DictionaryValue params;
+ scoped_ptr<base::Value> value;
+ // Zip file entry that contains a single file with contents 'COW\n', base64
+ // encoded following RFC 1521.
+ const char* kBase64ZipEntry =
+ "UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/"
+ "wAzG\nBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAA"
+ "AA\n";
+ params.SetString("file", kBase64ZipEntry);
+ Status status = ExecuteUploadFile(&session, params, &value);
+ ASSERT_EQ(kOk, status.code()) << status.message();
+ base::FilePath::StringType path;
+ ASSERT_TRUE(value->GetAsString(&path));
+ ASSERT_TRUE(base::PathExists(base::FilePath(path)));
+ std::string data;
+ ASSERT_TRUE(file_util::ReadFileToString(base::FilePath(path), &data));
+ ASSERT_STREQ("COW\n", data.c_str());
+}
+
namespace {
-Status ExecuteSimpleCommand(
- Session* expected_session,
- base::DictionaryValue* expected_params,
- base::Value* value,
- Session* session,
- const base::DictionaryValue& params,
- scoped_ptr<base::Value>* return_value) {
- EXPECT_EQ(expected_session, session);
- EXPECT_TRUE(expected_params->Equals(&params));
- return_value->reset(value->DeepCopy());
- return Status(kOk);
-}
+class DetachChrome : public StubChrome {
+ public:
+ DetachChrome() : quit_called_(false) {}
+ virtual ~DetachChrome() {}
+
+ // Overridden from Chrome:
+ virtual Status Quit() OVERRIDE {
+ quit_called_ = true;
+ return Status(kOk);
+ }
+
+ bool quit_called_;
+};
} // namespace
-TEST(SessionCommandTest, SimpleCommand) {
- SessionMap map;
- Session session("session", scoped_ptr<Chrome>(new StubChrome()));
- ASSERT_TRUE(session.thread.Start());
- scoped_refptr<SessionAccessor> accessor(new FakeSessionAccessor(&session));
- map.Set(session.id, accessor);
+TEST(SessionCommandsTest, Quit) {
+ DetachChrome* chrome = new DetachChrome();
+ Session session("id", scoped_ptr<Chrome>(chrome));
base::DictionaryValue params;
- params.SetInteger("param", 5);
- base::FundamentalValue expected_value(6);
- SessionCommand cmd = base::Bind(
- &ExecuteSimpleCommand, &session, &params, &expected_value);
-
scoped_ptr<base::Value> value;
- std::string session_id;
- Status status = ExecuteSessionCommand(
- &map, cmd, params,
- session.id, &value, &session_id);
- ASSERT_EQ(kOk, status.code());
- ASSERT_TRUE(expected_value.Equals(value.get()));
- ASSERT_STREQ(session.id.c_str(), session_id.c_str());
-}
-namespace {
+ ASSERT_EQ(kOk, ExecuteQuit(false, &session, params, &value).code());
+ ASSERT_TRUE(chrome->quit_called_);
-Status ShouldNotBeCalled(
- Session* session,
- const base::DictionaryValue& params,
- scoped_ptr<base::Value>* value) {
- EXPECT_TRUE(false);
- return Status(kOk);
+ chrome->quit_called_ = false;
+ ASSERT_EQ(kOk, ExecuteQuit(true, &session, params, &value).code());
+ ASSERT_TRUE(chrome->quit_called_);
}
-} // namespace
+TEST(SessionCommandsTest, QuitWithDetach) {
+ DetachChrome* chrome = new DetachChrome();
+ Session session("id", scoped_ptr<Chrome>(chrome));
+ session.detach = true;
-TEST(SessionCommandTest, NoSuchSession) {
- SessionMap map;
base::DictionaryValue params;
scoped_ptr<base::Value> value;
- std::string session_id;
- Status status = ExecuteSessionCommand(
- &map, base::Bind(&ShouldNotBeCalled), params,
- "session", &value, &session_id);
- ASSERT_EQ(kNoSuchSession, status.code());
- ASSERT_FALSE(value.get());
- ASSERT_STREQ("session", session_id.c_str());
-}
-TEST(SessionCommandTest, SessionDeletedWhileWaiting) {
- SessionMap map;
- scoped_refptr<SessionAccessor> accessor(new FakeSessionAccessor(NULL));
- map.Set("session", accessor);
+ ASSERT_EQ(kOk, ExecuteQuit(true, &session, params, &value).code());
+ ASSERT_FALSE(chrome->quit_called_);
- base::DictionaryValue params;
- scoped_ptr<base::Value> value;
- std::string session_id;
- Status status = ExecuteSessionCommand(
- &map, base::Bind(&ShouldNotBeCalled), params,
- "session", &value, &session_id);
- ASSERT_EQ(kNoSuchSession, status.code());
- ASSERT_FALSE(value.get());
- ASSERT_STREQ("session", session_id.c_str());
+ ASSERT_EQ(kOk, ExecuteQuit(false, &session, params, &value).code());
+ ASSERT_TRUE(chrome->quit_called_);
}
-TEST(SessionCommandTest, FileUpload) {
- Session session("id");
+namespace {
+
+class FailsToQuitChrome : public StubChrome {
+ public:
+ FailsToQuitChrome() {}
+ virtual ~FailsToQuitChrome() {}
+
+ // Overridden from Chrome:
+ virtual Status Quit() OVERRIDE {
+ return Status(kUnknownError);
+ }
+};
+
+} // namespace
+
+TEST(SessionCommandsTest, QuitFails) {
+ Session session("id", scoped_ptr<Chrome>(new FailsToQuitChrome()));
base::DictionaryValue params;
scoped_ptr<base::Value> value;
- // Zip file entry that contains a single file with contents 'COW\n', base64
- // encoded following RFC 1521.
- const char* kBase64ZipEntry =
- "UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/"
- "wAzG\nBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAA"
- "AA\n";
- params.SetString("file", kBase64ZipEntry);
- Status status = ExecuteUploadFile(&session, params, &value);
- ASSERT_EQ(kOk, status.code()) << status.message();
- base::FilePath::StringType path;
- ASSERT_TRUE(value->GetAsString(&path));
- ASSERT_TRUE(base::PathExists(base::FilePath(path)));
- std::string data;
- ASSERT_TRUE(file_util::ReadFileToString(base::FilePath(path), &data));
- ASSERT_STREQ("COW\n", data.c_str());
+ ASSERT_EQ(kUnknownError, ExecuteQuit(false, &session, params, &value).code());
}
« no previous file with comments | « chrome/test/chromedriver/session_commands.cc ('k') | chrome/test/chromedriver/session_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698