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

Side by Side Diff: chrome/browser/extensions/extension_browsertests_misc.cc

Issue 6413031: Merge 73784 - Reland r73760: Move most of chrome-extension:// request... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/648/src/
Patch Set: Created 9 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/ref_counted.h" 6 #include "base/ref_counted.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/extensions/autoupdate_interceptor.h" 9 #include "chrome/browser/extensions/autoupdate_interceptor.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if ((*iter)->GetURL().path() == path) { 72 if ((*iter)->GetURL().path() == path) {
73 EXPECT_FALSE(host); 73 EXPECT_FALSE(host);
74 host = *iter; 74 host = *iter;
75 } 75 }
76 num_hosts++; 76 num_hosts++;
77 } 77 }
78 EXPECT_EQ(expected_hosts, num_hosts); 78 EXPECT_EQ(expected_hosts, num_hosts);
79 return host; 79 return host;
80 } 80 }
81 81
82 // Tests that extension resources can be loaded from origins which the
83 // extension specifies in permissions but not from others.
84 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, OriginPrivileges) {
85 host_resolver()->AddRule("*", "127.0.0.1");
86 ASSERT_TRUE(test_server()->Start());
87 ASSERT_TRUE(LoadExtension(test_data_dir_
88 .AppendASCII("origin_privileges").AppendASCII("extension")));
89
90 GURL origin_privileges_index(
91 test_server()->GetURL("files/extensions/origin_privileges/index.html"));
92
93 std::string host_a("a.com");
94 GURL::Replacements make_host_a_com;
95 make_host_a_com.SetHostStr(host_a);
96
97 std::string host_b("b.com");
98 GURL::Replacements make_host_b_com;
99 make_host_b_com.SetHostStr(host_b);
100
101 // A web host that has permission.
102 ui_test_utils::NavigateToURL(
103 browser(), origin_privileges_index.ReplaceComponents(make_host_a_com));
104 std::string result;
105 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
106 browser()->GetSelectedTabContents()->render_view_host(), L"",
107 L"window.domAutomationController.send(document.title)",
108 &result));
109 EXPECT_EQ(result, "Loaded");
110
111 // A web host that does not have permission.
112 ui_test_utils::NavigateToURL(
113 browser(), origin_privileges_index.ReplaceComponents(make_host_b_com));
114 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
115 browser()->GetSelectedTabContents()->render_view_host(), L"",
116 L"window.domAutomationController.send(document.title)",
117 &result));
118 EXPECT_EQ(result, "Image failed to load");
119
120 // A data URL. Data URLs should always be able to load chrome-extension://
121 // resources.
122 std::string file_source;
123 ASSERT_TRUE(file_util::ReadFileToString(
124 test_data_dir_.AppendASCII("origin_privileges")
125 .AppendASCII("index.html"), &file_source));
126 ui_test_utils::NavigateToURL(browser(),
127 GURL(std::string("data:text/html;charset=utf-8,") + file_source));
128 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
129 browser()->GetSelectedTabContents()->render_view_host(), L"",
130 L"window.domAutomationController.send(document.title)",
131 &result));
132 EXPECT_EQ(result, "Loaded");
133
134 // A different extension. Extensions should always be able to load each
135 // other's resources.
136 ASSERT_TRUE(LoadExtension(test_data_dir_
137 .AppendASCII("origin_privileges").AppendASCII("extension2")));
138 ui_test_utils::NavigateToURL(
139 browser(),
140 GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html"));
141 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
142 browser()->GetSelectedTabContents()->render_view_host(), L"",
143 L"window.domAutomationController.send(document.title)",
144 &result));
145 EXPECT_EQ(result, "Loaded");
146 }
147
148 // Tests that we can load extension pages into the tab area and they can call 82 // Tests that we can load extension pages into the tab area and they can call
149 // extension APIs. 83 // extension APIs.
150 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { 84 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) {
151 ASSERT_TRUE(LoadExtension( 85 ASSERT_TRUE(LoadExtension(
152 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 86 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
153 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 87 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
154 .AppendASCII("1.0.0.0"))); 88 .AppendASCII("1.0.0.0")));
155 89
156 ui_test_utils::NavigateToURL( 90 ui_test_utils::NavigateToURL(
157 browser(), 91 browser(),
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 L" window.chrome.app.isInstalled = false;" 854 L" window.chrome.app.isInstalled = false;"
921 L" return 'BAD: Should have thrown by now...';" 855 L" return 'BAD: Should have thrown by now...';"
922 L" } catch (e) {" 856 L" } catch (e) {"
923 L" return 'GOOD: Saw expected error.';" 857 L" return 'GOOD: Saw expected error.';"
924 L" }" 858 L" }"
925 L" }()" 859 L" }()"
926 L");", 860 L");",
927 &result)); 861 &result));
928 EXPECT_EQ("GOOD: Saw expected error.", result); 862 EXPECT_EQ("GOOD: Saw expected error.", result);
929 } 863 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.cc ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698