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 "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
| 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class ClipboardApiTest : public ExtensionApiTest { | 18 class ClipboardApiTest : public ExtensionApiTest { |
18 public: | 19 public: |
19 bool LoadHostedApp(const std::string& app_name, | 20 bool LoadHostedApp(const std::string& app_name, |
20 const std::string& launch_page); | 21 const std::string& launch_page); |
21 bool ExecuteCopyInSelectedTab(bool* result); | 22 bool ExecuteCopyInSelectedTab(bool* result); |
22 bool ExecutePasteInSelectedTab(bool* result); | 23 bool ExecutePasteInSelectedTab(bool* result); |
23 | 24 |
24 private: | 25 private: |
25 bool ExecuteScriptInSelectedTab(const std::string& script, bool* result); | 26 bool ExecuteScriptInSelectedTab(const std::string& script, bool* result); |
26 }; | 27 }; |
27 | 28 |
28 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, | 29 bool ClipboardApiTest::LoadHostedApp(const std::string& app_name, |
29 const std::string& launch_page) { | 30 const std::string& launch_page) { |
30 host_resolver()->AddRule("*", "127.0.0.1"); | 31 host_resolver()->AddRule("*", "127.0.0.1"); |
31 | 32 |
32 if (!StartTestServer()) { | 33 if (!StartTestServer()) { |
33 message_ = "Failed to start test server."; | 34 message_ = "Failed to start test server."; |
34 return false; | 35 return false; |
35 } | 36 } |
36 | 37 |
37 if (!LoadExtension(test_data_dir_.AppendASCII("clipboard") | 38 if (!LoadExtension(test_data_dir_.AppendASCII("clipboard") |
38 .AppendASCII(app_name))) { | 39 .AppendASCII(app_name))) { |
39 message_ = "Failed to load hosted app."; | 40 message_ = "Failed to load hosted app."; |
40 return false; | 41 return false; |
41 } | 42 } |
42 | 43 |
43 GURL base_url = test_server()->GetURL("files/extensions/api_test/clipboard/"); | 44 GURL base_url = embedded_test_server()->GetURL( |
| 45 "/extensions/api_test/clipboard/"); |
44 GURL::Replacements replace_host; | 46 GURL::Replacements replace_host; |
45 std::string host_str("localhost"); // Must stay in scope with replace_host. | 47 std::string host_str("localhost"); // Must stay in scope with replace_host. |
46 replace_host.SetHostStr(host_str); | 48 replace_host.SetHostStr(host_str); |
47 base_url = base_url.ReplaceComponents(replace_host); | 49 base_url = base_url.ReplaceComponents(replace_host); |
48 | 50 |
49 std::string launch_page_path = | 51 std::string launch_page_path = |
50 base::StringPrintf("%s/%s", app_name.c_str(), launch_page.c_str()); | 52 base::StringPrintf("%s/%s", app_name.c_str(), launch_page.c_str()); |
51 ui_test_utils::NavigateToURL(browser(), base_url.Resolve(launch_page_path)); | 53 ui_test_utils::NavigateToURL(browser(), base_url.Resolve(launch_page_path)); |
52 | 54 |
53 return true; | 55 return true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) | 106 ASSERT_TRUE(LoadHostedApp("hosted_app_no_permission", "main.html")) |
105 << message_; | 107 << message_; |
106 | 108 |
107 bool result = false; | 109 bool result = false; |
108 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; | 110 ASSERT_TRUE(ExecuteCopyInSelectedTab(&result)) << message_; |
109 EXPECT_FALSE(result); | 111 EXPECT_FALSE(result); |
110 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; | 112 ASSERT_TRUE(ExecutePasteInSelectedTab(&result)) << message_; |
111 EXPECT_FALSE(result); | 113 EXPECT_FALSE(result); |
112 } | 114 } |
113 | 115 |
OLD | NEW |