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

Side by Side Diff: ios/web/webui/crw_web_ui_manager_unittest.mm

Issue 2583963002: Remove WebUI favicon support on iOS (Closed)
Patch Set: Remove web_ui_favicons.js from BUILD.gn Created 4 years 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
« no previous file with comments | « ios/web/webui/crw_web_ui_manager.mm ('k') | ios/web/webui/resources/web_ui_bundle.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #import "ios/web/webui/crw_web_ui_manager.h" 5 #import "ios/web/webui/crw_web_ui_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Tests that CRWWebUIManager observes provisional navigation and invokes an 142 // Tests that CRWWebUIManager observes provisional navigation and invokes an
143 // HTML load in web state. 143 // HTML load in web state.
144 TEST_F(CRWWebUIManagerTest, LoadWebUI) { 144 TEST_F(CRWWebUIManagerTest, LoadWebUI) {
145 base::string16 html(base::SysNSStringToUTF16(kHtml)); 145 base::string16 html(base::SysNSStringToUTF16(kHtml));
146 GURL url(kTestWebUIUrl); 146 GURL url(kTestWebUIUrl);
147 EXPECT_CALL(*web_state_impl_, LoadWebUIHtml(html, url)); 147 EXPECT_CALL(*web_state_impl_, LoadWebUIHtml(html, url));
148 web_state_impl_->OnProvisionalNavigationStarted(url); 148 web_state_impl_->OnProvisionalNavigationStarted(url);
149 } 149 }
150 150
151 // Tests that CRWWebUIManager responds to OnScriptCommandReceieved call and runs 151 // Tests that CRWWebUIManager responds to OnScriptCommandReceieved call and runs
152 // JavaScript to set favicon background.
153 TEST_F(CRWWebUIManagerTest, HandleFaviconRequest) {
154 GURL test_url(kTestWebUIUrl);
155 std::string favicon_url_string(kFaviconUrl);
156
157 // Create mock JavaScript message to request favicon.
158 base::ListValue* arguments(new base::ListValue());
159 arguments->AppendString(favicon_url_string);
160 std::unique_ptr<base::DictionaryValue> message(new base::DictionaryValue());
161 message->SetString("message", "webui.requestFavicon");
162 message->Set("arguments", arguments);
163
164 // Create expected JavaScript to call.
165 base::FilePath favicon_path;
166 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &favicon_path));
167 favicon_path = favicon_path.AppendASCII(kFaviconPath);
168 NSData* expected_data = [NSData
169 dataWithContentsOfFile:base::SysUTF8ToNSString(favicon_path.value())];
170 base::string16 expected_javascript = base::SysNSStringToUTF16([NSString
171 stringWithFormat:
172 @"chrome.setFaviconBackground('%s', 'data:image/png;base64,%@');",
173 favicon_url_string.c_str(),
174 [expected_data base64EncodedStringWithOptions:0]]);
175
176 EXPECT_CALL(*web_state_impl_, ExecuteJavaScript(expected_javascript));
177 web_state_impl_->OnScriptCommandReceived("webui.requestFavicon", *message,
178 test_url, false);
179 }
180
181 // Tests that CRWWebUIManager responds to OnScriptCommandReceieved call and runs
182 // JavaScript to fetch a mojo resource. 152 // JavaScript to fetch a mojo resource.
183 TEST_F(CRWWebUIManagerTest, HandleLoadMojoRequest) { 153 TEST_F(CRWWebUIManagerTest, HandleLoadMojoRequest) {
184 // Create mock JavaScript message to request a mojo resource. 154 // Create mock JavaScript message to request a mojo resource.
185 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); 155 std::unique_ptr<base::ListValue> arguments(new base::ListValue());
186 arguments->AppendString(kMojoModuleName); 156 arguments->AppendString(kMojoModuleName);
187 const char kTestLoadId[] = "test-load-id"; 157 const char kTestLoadId[] = "test-load-id";
188 arguments->AppendString(kTestLoadId); 158 arguments->AppendString(kTestLoadId);
189 base::DictionaryValue message; 159 base::DictionaryValue message;
190 message.SetString("message", "webui.loadMojo"); 160 message.SetString("message", "webui.loadMojo");
191 message.Set("arguments", std::move(arguments)); 161 message.Set("arguments", std::move(arguments));
192 162
193 // Create expected JavaScript to call. 163 // Create expected JavaScript to call.
194 std::string expected_javascript = base::StringPrintf( 164 std::string expected_javascript = base::StringPrintf(
195 "%s__crWeb.webUIModuleLoadNotifier.moduleLoadCompleted(\"%s\", \"%s\");", 165 "%s__crWeb.webUIModuleLoadNotifier.moduleLoadCompleted(\"%s\", \"%s\");",
196 base::SysNSStringToUTF8(kMojoModule).c_str(), kMojoModuleName, 166 base::SysNSStringToUTF8(kMojoModule).c_str(), kMojoModuleName,
197 kTestLoadId); 167 kTestLoadId);
198 168
199 EXPECT_CALL(*web_state_impl_, 169 EXPECT_CALL(*web_state_impl_,
200 ExecuteJavaScript(base::UTF8ToUTF16(expected_javascript))); 170 ExecuteJavaScript(base::UTF8ToUTF16(expected_javascript)));
201 web_state_impl_->OnScriptCommandReceived("webui.loadMojo", message, 171 web_state_impl_->OnScriptCommandReceived("webui.loadMojo", message,
202 GURL(kTestWebUIUrl), false); 172 GURL(kTestWebUIUrl), false);
203 } 173 }
204 } // namespace web 174 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/webui/crw_web_ui_manager.mm ('k') | ios/web/webui/resources/web_ui_bundle.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698