OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/ui_test_utils.h" | 9 #include "chrome/test/ui_test_utils.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 "index.html")); | 29 "index.html")); |
30 | 30 |
31 std::string host_a("a.com"); | 31 std::string host_a("a.com"); |
32 GURL::Replacements make_host_a_com; | 32 GURL::Replacements make_host_a_com; |
33 make_host_a_com.SetHostStr(host_a); | 33 make_host_a_com.SetHostStr(host_a); |
34 | 34 |
35 std::string host_b("b.com"); | 35 std::string host_b("b.com"); |
36 GURL::Replacements make_host_b_com; | 36 GURL::Replacements make_host_b_com; |
37 make_host_b_com.SetHostStr(host_b); | 37 make_host_b_com.SetHostStr(host_b); |
38 | 38 |
| 39 std::string host_c("c.com"); |
| 40 GURL::Replacements make_host_c_com; |
| 41 make_host_c_com.SetHostStr(host_c); |
| 42 |
39 // A web host that has permission. | 43 // A web host that has permission. |
40 ui_test_utils::NavigateToURL( | 44 ui_test_utils::NavigateToURL( |
41 browser(), web_resource.ReplaceComponents(make_host_a_com)); | 45 browser(), web_resource.ReplaceComponents(make_host_a_com)); |
42 std::string result; | 46 std::string result; |
43 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 47 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
44 browser()->GetSelectedTabContents()->render_view_host(), L"", | 48 browser()->GetSelectedTabContents()->render_view_host(), L"", |
45 L"window.domAutomationController.send(document.title)", | 49 L"window.domAutomationController.send(document.title)", |
46 &result)); | 50 &result)); |
47 EXPECT_EQ(result, "Loaded"); | 51 EXPECT_EQ(result, "Loaded"); |
48 | 52 |
49 // A web host that does not have permission. | 53 // A web host that does not have permission. |
50 ui_test_utils::NavigateToURL( | 54 ui_test_utils::NavigateToURL( |
51 browser(), web_resource.ReplaceComponents(make_host_b_com)); | 55 browser(), web_resource.ReplaceComponents(make_host_b_com)); |
52 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 56 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
53 browser()->GetSelectedTabContents()->render_view_host(), L"", | 57 browser()->GetSelectedTabContents()->render_view_host(), L"", |
54 L"window.domAutomationController.send(document.title)", | 58 L"window.domAutomationController.send(document.title)", |
55 &result)); | 59 &result)); |
56 EXPECT_EQ(result, "Image failed to load"); | 60 EXPECT_EQ(result, "Image failed to load"); |
57 | 61 |
| 62 // A web host that has permissions only through content scripts. |
| 63 ui_test_utils::NavigateToURL( |
| 64 browser(), web_resource.ReplaceComponents(make_host_c_com)); |
| 65 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 66 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 67 L"window.domAutomationController.send(document.title)", |
| 68 &result)); |
| 69 EXPECT_EQ(result, "Loaded"); |
| 70 |
| 71 // A web host asking for an unknown extension. |
| 72 GURL unknown_extension_test( |
| 73 test_server()->GetURL( |
| 74 "files/extensions/api_test/extension_resource_request_policy/" |
| 75 "unknown_extension.html")); |
| 76 ui_test_utils::NavigateToURL(browser(), unknown_extension_test); |
| 77 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 78 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 79 L"window.domAutomationController.send(document.title)", |
| 80 &result)); |
| 81 EXPECT_EQ(result, "Image failed to load"); |
| 82 |
58 // A data URL. Data URLs should always be able to load chrome-extension:// | 83 // A data URL. Data URLs should always be able to load chrome-extension:// |
59 // resources. | 84 // resources. |
60 std::string file_source; | 85 std::string file_source; |
61 ASSERT_TRUE(file_util::ReadFileToString( | 86 ASSERT_TRUE(file_util::ReadFileToString( |
62 test_data_dir_.AppendASCII("extension_resource_request_policy") | 87 test_data_dir_.AppendASCII("extension_resource_request_policy") |
63 .AppendASCII("index.html"), &file_source)); | 88 .AppendASCII("index.html"), &file_source)); |
64 ui_test_utils::NavigateToURL(browser(), | 89 ui_test_utils::NavigateToURL(browser(), |
65 GURL(std::string("data:text/html;charset=utf-8,") + file_source)); | 90 GURL(std::string("data:text/html;charset=utf-8,") + file_source)); |
66 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 91 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
67 browser()->GetSelectedTabContents()->render_view_host(), L"", | 92 browser()->GetSelectedTabContents()->render_view_host(), L"", |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 EXPECT_TRUE(RunExtensionSubtest( | 124 EXPECT_TRUE(RunExtensionSubtest( |
100 "extension_resource_request_policy/extension2", | 125 "extension_resource_request_policy/extension2", |
101 "audio.html")); | 126 "audio.html")); |
102 } | 127 } |
103 | 128 |
104 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Video) { | 129 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Video) { |
105 EXPECT_TRUE(RunExtensionSubtest( | 130 EXPECT_TRUE(RunExtensionSubtest( |
106 "extension_resource_request_policy/extension2", | 131 "extension_resource_request_policy/extension2", |
107 "video.html")); | 132 "video.html")); |
108 } | 133 } |
| 134 |
| 135 IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, AboutBlankIframe) { |
| 136 EXPECT_TRUE(RunExtensionSubtest( |
| 137 "extension_resource_request_policy/extension2", |
| 138 "about_blank_iframe.html")); |
| 139 } |
OLD | NEW |