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

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

Issue 2879413002: Pass NavigationContext to WebStateImpl::OnNavigationStarted. (Closed)
Patch Set: Fixed tests Created 3 years, 7 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
« no previous file with comments | « ios/web/web_state/web_state_impl_unittest.mm ('k') | no next file » | 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #import "base/strings/sys_string_conversions.h" 17 #import "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "ios/web/public/test/fakes/test_browser_state.h" 20 #include "ios/web/public/test/fakes/test_browser_state.h"
21 #import "ios/web/public/test/fakes/test_web_client.h" 21 #import "ios/web/public/test/fakes/test_web_client.h"
22 #include "ios/web/public/test/scoped_testing_web_client.h" 22 #include "ios/web/public/test/scoped_testing_web_client.h"
23 #include "ios/web/public/test/web_test.h" 23 #include "ios/web/public/test/web_test.h"
24 #include "ios/web/web_state/navigation_context_impl.h"
24 #import "ios/web/web_state/web_state_impl.h" 25 #import "ios/web/web_state/web_state_impl.h"
25 #import "ios/web/webui/crw_web_ui_page_builder.h" 26 #import "ios/web/webui/crw_web_ui_page_builder.h"
26 #import "ios/web/webui/url_fetcher_block_adapter.h" 27 #import "ios/web/webui/url_fetcher_block_adapter.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #import "testing/gtest_mac.h" 30 #import "testing/gtest_mac.h"
30 31
31 namespace web { 32 namespace web {
32 33
33 // Path for test favicon file. 34 // Path for test favicon file.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // WebUIManager for testing. 140 // WebUIManager for testing.
140 base::scoped_nsobject<CRWTestWebUIManager> web_ui_manager_; 141 base::scoped_nsobject<CRWTestWebUIManager> web_ui_manager_;
141 }; 142 };
142 143
143 // Tests that CRWWebUIManager observes provisional navigation and invokes an 144 // Tests that CRWWebUIManager observes provisional navigation and invokes an
144 // HTML load in web state. 145 // HTML load in web state.
145 TEST_F(CRWWebUIManagerTest, LoadWebUI) { 146 TEST_F(CRWWebUIManagerTest, LoadWebUI) {
146 base::string16 html(base::SysNSStringToUTF16(kHtml)); 147 base::string16 html(base::SysNSStringToUTF16(kHtml));
147 GURL url(kTestWebUIUrl); 148 GURL url(kTestWebUIUrl);
148 EXPECT_CALL(*web_state_impl_, LoadWebUIHtml(html, url)); 149 EXPECT_CALL(*web_state_impl_, LoadWebUIHtml(html, url));
149 web_state_impl_->OnProvisionalNavigationStarted(url); 150 std::unique_ptr<web::NavigationContext> context =
151 NavigationContextImpl::CreateNavigationContext(web_state_impl_.get(),
152 url);
153 web_state_impl_->OnNavigationStarted(context.get());
150 } 154 }
151 155
152 // Tests that CRWWebUIManager responds to OnScriptCommandReceieved call and runs 156 // Tests that CRWWebUIManager responds to OnScriptCommandReceieved call and runs
153 // JavaScript to fetch a mojo resource. 157 // JavaScript to fetch a mojo resource.
154 TEST_F(CRWWebUIManagerTest, HandleLoadMojoRequest) { 158 TEST_F(CRWWebUIManagerTest, HandleLoadMojoRequest) {
155 // Create mock JavaScript message to request a mojo resource. 159 // Create mock JavaScript message to request a mojo resource.
156 std::unique_ptr<base::ListValue> arguments(new base::ListValue()); 160 std::unique_ptr<base::ListValue> arguments(new base::ListValue());
157 arguments->AppendString(kMojoModuleName); 161 arguments->AppendString(kMojoModuleName);
158 const char kTestLoadId[] = "test-load-id"; 162 const char kTestLoadId[] = "test-load-id";
159 arguments->AppendString(kTestLoadId); 163 arguments->AppendString(kTestLoadId);
160 base::DictionaryValue message; 164 base::DictionaryValue message;
161 message.SetString("message", "webui.loadMojo"); 165 message.SetString("message", "webui.loadMojo");
162 message.Set("arguments", std::move(arguments)); 166 message.Set("arguments", std::move(arguments));
163 167
164 // Create expected JavaScript to call. 168 // Create expected JavaScript to call.
165 std::string expected_javascript = base::StringPrintf( 169 std::string expected_javascript = base::StringPrintf(
166 "%s__crWeb.webUIModuleLoadNotifier.moduleLoadCompleted(\"%s\", \"%s\");", 170 "%s__crWeb.webUIModuleLoadNotifier.moduleLoadCompleted(\"%s\", \"%s\");",
167 base::SysNSStringToUTF8(kMojoModule).c_str(), kMojoModuleName, 171 base::SysNSStringToUTF8(kMojoModule).c_str(), kMojoModuleName,
168 kTestLoadId); 172 kTestLoadId);
169 173
170 EXPECT_CALL(*web_state_impl_, 174 EXPECT_CALL(*web_state_impl_,
171 ExecuteJavaScript(base::UTF8ToUTF16(expected_javascript))); 175 ExecuteJavaScript(base::UTF8ToUTF16(expected_javascript)));
172 web_state_impl_->OnScriptCommandReceived("webui.loadMojo", message, 176 web_state_impl_->OnScriptCommandReceived("webui.loadMojo", message,
173 GURL(kTestWebUIUrl), false); 177 GURL(kTestWebUIUrl), false);
174 } 178 }
175 } // namespace web 179 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/web_state_impl_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698