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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
12 #include "net/dns/mock_host_resolver.h" | 12 #include "net/dns/mock_host_resolver.h" |
13 #include "net/test/embedded_test_server/embedded_test_server.h" | 13 #include "net/test/embedded_test_server/embedded_test_server.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class ClipboardApiTest : public ExtensionApiTest { | 18 class ClipboardApiTest : public ExtensionApiTest { |
19 public: | 19 public: |
| 20 void SetUpOnMainThread() override { |
| 21 ExtensionApiTest::SetUpOnMainThread(); |
| 22 host_resolver()->AddRule("*", "127.0.0.1"); |
| 23 } |
| 24 |
20 bool LoadHostedApp(const std::string& app_name, | 25 bool LoadHostedApp(const std::string& app_name, |
21 const std::string& launch_page); | 26 const std::string& launch_page); |
22 bool ExecuteCopyInSelectedTab(); | 27 bool ExecuteCopyInSelectedTab(); |
23 bool ExecutePasteInSelectedTab(); | 28 bool ExecutePasteInSelectedTab(); |
24 bool ExecuteCommandInIframeInSelectedTab(const char* command); | 29 bool ExecuteCommandInIframeInSelectedTab(const char* command); |
25 | 30 |
26 private: | 31 private: |
27 bool ExecuteScriptInSelectedTab(const std::string& script); | 32 bool ExecuteScriptInSelectedTab(const std::string& script); |
28 }; | 33 }; |
29 | 34 |
30 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, | 35 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, |
31 const std::string& launch_page) { | 36 const std::string& launch_page) { |
32 host_resolver()->AddRule("*", "127.0.0.1"); | |
33 | |
34 if (!StartEmbeddedTestServer()) { | 37 if (!StartEmbeddedTestServer()) { |
35 message_ = "Failed to start test server."; | 38 message_ = "Failed to start test server."; |
36 return false; | 39 return false; |
37 } | 40 } |
38 | 41 |
39 if (!LoadExtension(test_data_dir_.AppendASCII("clipboard") | 42 if (!LoadExtension(test_data_dir_.AppendASCII("clipboard") |
40 .AppendASCII(app_name))) { | 43 .AppendASCII(app_name))) { |
41 message_ = "Failed to load hosted app."; | 44 message_ = "Failed to load hosted app."; |
42 return false; | 45 return false; |
43 } | 46 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 117 |
115 // TODO(dcheng): The test coverage here is incomplete. The content test utils | 118 // TODO(dcheng): The test coverage here is incomplete. The content test utils |
116 // for executing script force a user gesture, so it's impossible to test | 119 // for executing script force a user gesture, so it's impossible to test |
117 // the no user gesture case without a lot of code duplication. | 120 // the no user gesture case without a lot of code duplication. |
118 EXPECT_TRUE(ExecuteCopyInSelectedTab()) << message_; | 121 EXPECT_TRUE(ExecuteCopyInSelectedTab()) << message_; |
119 EXPECT_FALSE(ExecutePasteInSelectedTab()) << message_; | 122 EXPECT_FALSE(ExecutePasteInSelectedTab()) << message_; |
120 EXPECT_TRUE(ExecuteCommandInIframeInSelectedTab("copy")) << message_; | 123 EXPECT_TRUE(ExecuteCommandInIframeInSelectedTab("copy")) << message_; |
121 EXPECT_FALSE(ExecuteCommandInIframeInSelectedTab("paste")) << message_; | 124 EXPECT_FALSE(ExecuteCommandInIframeInSelectedTab("paste")) << message_; |
122 } | 125 } |
123 | 126 |
OLD | NEW |