| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/zip.h" | 11 #include "chrome/common/zip.h" |
| 12 #include "chrome/test/webdriver/webdriver_capabilities_parser.h" | 12 #include "chrome/test/webdriver/webdriver_capabilities_parser.h" |
| 13 #include "chrome/test/webdriver/webdriver_logging.h" | 13 #include "chrome/test/webdriver/webdriver_logging.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using base::DictionaryValue; | 16 using base::DictionaryValue; |
| 17 using base::ListValue; | 17 using base::ListValue; |
| 18 using base::Value; | 18 using base::Value; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 DictionaryValue* options = new DictionaryValue(); | 31 DictionaryValue* options = new DictionaryValue(); |
| 32 dict.Set("chromeOptions", options); | 32 dict.Set("chromeOptions", options); |
| 33 | 33 |
| 34 options->SetString("binary", "binary"); | 34 options->SetString("binary", "binary"); |
| 35 options->SetString("channel", "channel"); | 35 options->SetString("channel", "channel"); |
| 36 options->SetBoolean("detach", true); | 36 options->SetBoolean("detach", true); |
| 37 options->SetBoolean("loadAsync", true); | 37 options->SetBoolean("loadAsync", true); |
| 38 options->SetBoolean("nativeEvents", true); | 38 options->SetBoolean("nativeEvents", true); |
| 39 | 39 |
| 40 Capabilities caps; | 40 Capabilities caps; |
| 41 ScopedTempDir temp_dir; | 41 base::ScopedTempDir temp_dir; |
| 42 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 42 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 43 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); | 43 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); |
| 44 ASSERT_FALSE(parser.Parse()); | 44 ASSERT_FALSE(parser.Parse()); |
| 45 EXPECT_EQ(FILE_PATH_LITERAL("binary"), caps.command.GetProgram().value()); | 45 EXPECT_EQ(FILE_PATH_LITERAL("binary"), caps.command.GetProgram().value()); |
| 46 EXPECT_STREQ("channel", caps.channel.c_str()); | 46 EXPECT_STREQ("channel", caps.channel.c_str()); |
| 47 EXPECT_TRUE(caps.detach); | 47 EXPECT_TRUE(caps.detach); |
| 48 EXPECT_TRUE(caps.load_async); | 48 EXPECT_TRUE(caps.load_async); |
| 49 EXPECT_TRUE(caps.native_events); | 49 EXPECT_TRUE(caps.native_events); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST(CapabilitiesParser, Args) { | 52 TEST(CapabilitiesParser, Args) { |
| 53 DictionaryValue dict; | 53 DictionaryValue dict; |
| 54 DictionaryValue* options = new DictionaryValue(); | 54 DictionaryValue* options = new DictionaryValue(); |
| 55 dict.Set("chromeOptions", options); | 55 dict.Set("chromeOptions", options); |
| 56 | 56 |
| 57 ListValue* args = new ListValue(); | 57 ListValue* args = new ListValue(); |
| 58 args->Append(Value::CreateStringValue("arg1")); | 58 args->Append(Value::CreateStringValue("arg1")); |
| 59 args->Append(Value::CreateStringValue("arg2=val")); | 59 args->Append(Value::CreateStringValue("arg2=val")); |
| 60 args->Append(Value::CreateStringValue("arg3='a space'")); | 60 args->Append(Value::CreateStringValue("arg3='a space'")); |
| 61 options->Set("args", args); | 61 options->Set("args", args); |
| 62 | 62 |
| 63 Capabilities caps; | 63 Capabilities caps; |
| 64 ScopedTempDir temp_dir; | 64 base::ScopedTempDir temp_dir; |
| 65 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 65 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 66 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); | 66 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); |
| 67 ASSERT_FALSE(parser.Parse()); | 67 ASSERT_FALSE(parser.Parse()); |
| 68 EXPECT_TRUE(caps.command.HasSwitch("arg1")); | 68 EXPECT_TRUE(caps.command.HasSwitch("arg1")); |
| 69 EXPECT_STREQ("val", caps.command.GetSwitchValueASCII("arg2").c_str()); | 69 EXPECT_STREQ("val", caps.command.GetSwitchValueASCII("arg2").c_str()); |
| 70 EXPECT_STREQ("'a space'", caps.command.GetSwitchValueASCII("arg3").c_str()); | 70 EXPECT_STREQ("'a space'", caps.command.GetSwitchValueASCII("arg3").c_str()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(CapabilitiesParser, Extensions) { | 73 TEST(CapabilitiesParser, Extensions) { |
| 74 DictionaryValue dict; | 74 DictionaryValue dict; |
| 75 DictionaryValue* options = new DictionaryValue(); | 75 DictionaryValue* options = new DictionaryValue(); |
| 76 dict.Set("chromeOptions", options); | 76 dict.Set("chromeOptions", options); |
| 77 | 77 |
| 78 ListValue* extensions = new ListValue(); | 78 ListValue* extensions = new ListValue(); |
| 79 extensions->Append(Value::CreateStringValue("TWFu")); | 79 extensions->Append(Value::CreateStringValue("TWFu")); |
| 80 extensions->Append(Value::CreateStringValue("TWFuTWFu")); | 80 extensions->Append(Value::CreateStringValue("TWFuTWFu")); |
| 81 options->Set("extensions", extensions); | 81 options->Set("extensions", extensions); |
| 82 | 82 |
| 83 Capabilities caps; | 83 Capabilities caps; |
| 84 ScopedTempDir temp_dir; | 84 base::ScopedTempDir temp_dir; |
| 85 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 85 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 86 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); | 86 CapabilitiesParser parser(&dict, temp_dir.path(), Logger(), &caps); |
| 87 ASSERT_FALSE(parser.Parse()); | 87 ASSERT_FALSE(parser.Parse()); |
| 88 ASSERT_EQ(2u, caps.extensions.size()); | 88 ASSERT_EQ(2u, caps.extensions.size()); |
| 89 std::string contents; | 89 std::string contents; |
| 90 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[0], &contents)); | 90 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[0], &contents)); |
| 91 EXPECT_STREQ("Man", contents.c_str()); | 91 EXPECT_STREQ("Man", contents.c_str()); |
| 92 contents.clear(); | 92 contents.clear(); |
| 93 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[1], &contents)); | 93 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[1], &contents)); |
| 94 EXPECT_STREQ("ManMan", contents.c_str()); | 94 EXPECT_STREQ("ManMan", contents.c_str()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(CapabilitiesParser, Profile) { | 97 TEST(CapabilitiesParser, Profile) { |
| 98 DictionaryValue dict; | 98 DictionaryValue dict; |
| 99 DictionaryValue* options = new DictionaryValue(); | 99 DictionaryValue* options = new DictionaryValue(); |
| 100 dict.Set("chromeOptions", options); | 100 dict.Set("chromeOptions", options); |
| 101 | 101 |
| 102 ScopedTempDir temp_dir; | 102 base::ScopedTempDir temp_dir; |
| 103 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 103 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 104 FilePath folder = temp_dir.path().AppendASCII("folder"); | 104 FilePath folder = temp_dir.path().AppendASCII("folder"); |
| 105 ASSERT_TRUE(file_util::CreateDirectory(folder)); | 105 ASSERT_TRUE(file_util::CreateDirectory(folder)); |
| 106 ASSERT_EQ(4, file_util::WriteFile( | 106 ASSERT_EQ(4, file_util::WriteFile( |
| 107 folder.AppendASCII("data"), "data", 4)); | 107 folder.AppendASCII("data"), "data", 4)); |
| 108 FilePath zip = temp_dir.path().AppendASCII("data.zip"); | 108 FilePath zip = temp_dir.path().AppendASCII("data.zip"); |
| 109 ASSERT_TRUE(zip::Zip(folder, zip, false /* include_hidden_files */)); | 109 ASSERT_TRUE(zip::Zip(folder, zip, false /* include_hidden_files */)); |
| 110 std::string contents; | 110 std::string contents; |
| 111 ASSERT_TRUE(file_util::ReadFileToString(zip, &contents)); | 111 ASSERT_TRUE(file_util::ReadFileToString(zip, &contents)); |
| 112 std::string base64; | 112 std::string base64; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ASSERT_FALSE(parser.Parse()); | 292 ASSERT_FALSE(parser.Parse()); |
| 293 | 293 |
| 294 const std::set<std::string>& rm_set = caps.exclude_switches; | 294 const std::set<std::string>& rm_set = caps.exclude_switches; |
| 295 EXPECT_EQ(static_cast<size_t>(3), rm_set.size()); | 295 EXPECT_EQ(static_cast<size_t>(3), rm_set.size()); |
| 296 ASSERT_TRUE(rm_set.find(switches::kNoFirstRun) != rm_set.end()); | 296 ASSERT_TRUE(rm_set.find(switches::kNoFirstRun) != rm_set.end()); |
| 297 ASSERT_TRUE(rm_set.find(switches::kDisableSync) != rm_set.end()); | 297 ASSERT_TRUE(rm_set.find(switches::kDisableSync) != rm_set.end()); |
| 298 ASSERT_TRUE(rm_set.find(switches::kDisableTranslate) != rm_set.end()); | 298 ASSERT_TRUE(rm_set.find(switches::kDisableTranslate) != rm_set.end()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace webdriver | 301 } // namespace webdriver |
| OLD | NEW |