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

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

Issue 2916473002: [ObjC ARC] Converts ios/web:web to ARC. (Closed)
Patch Set: Fixing silly mistake Created 3 years, 6 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/wk_web_view_security_util.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #import "ios/testing/wait_util.h" 10 #import "ios/testing/wait_util.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 private: 130 private:
131 // UI handler class which communicates with test WebUI page. 131 // UI handler class which communicates with test WebUI page.
132 TestUIHandler* ui_handler_; 132 TestUIHandler* ui_handler_;
133 }; 133 };
134 } // namespace 134 } // namespace
135 135
136 // A test fixture for verifying mojo comminication for WebUI. 136 // A test fixture for verifying mojo comminication for WebUI.
137 class WebUIMojoTest : public WebIntTest { 137 class WebUIMojoTest : public WebIntTest {
138 protected: 138 protected:
139 void SetUp() override { 139 void SetUp() override {
140 WebIntTest::SetUp(); 140 @autoreleasepool {
141 ui_handler_ = base::MakeUnique<TestUIHandler>(); 141 WebIntTest::SetUp();
142 web::WebState::CreateParams params(GetBrowserState()); 142 ui_handler_ = base::MakeUnique<TestUIHandler>();
143 web_state_ = base::MakeUnique<web::WebStateImpl>(params); 143 web::WebState::CreateParams params(GetBrowserState());
144 web_state_->GetNavigationManagerImpl().InitializeSession(); 144 web_state_ = base::MakeUnique<web::WebStateImpl>(params);
145 WebUIIOSControllerFactory::RegisterFactory( 145 web_state_->GetNavigationManagerImpl().InitializeSession();
146 new TestWebUIControllerFactory(ui_handler_.get())); 146 WebUIIOSControllerFactory::RegisterFactory(
147 new TestWebUIControllerFactory(ui_handler_.get()));
148 }
149 }
150
151 void TearDown() override {
152 @autoreleasepool {
153 web_state_.reset();
154 WebIntTest::TearDown();
155 }
147 } 156 }
148 157
149 // Returns WebState which loads test WebUI page. 158 // Returns WebState which loads test WebUI page.
150 WebStateImpl* web_state() { return web_state_.get(); } 159 WebStateImpl* web_state() { return web_state_.get(); }
151 // Returns UI handler which communicates with WebUI page. 160 // Returns UI handler which communicates with WebUI page.
152 TestUIHandler* test_ui_handler() { return ui_handler_.get(); } 161 TestUIHandler* test_ui_handler() { return ui_handler_.get(); }
153 162
154 private: 163 private:
155 std::unique_ptr<WebStateImpl> web_state_; 164 std::unique_ptr<WebStateImpl> web_state_;
156 std::unique_ptr<TestUIHandler> ui_handler_; 165 std::unique_ptr<TestUIHandler> ui_handler_;
157 }; 166 };
158 167
159 // Tests that JS can send messages to the native code and vice versa. 168 // Tests that JS can send messages to the native code and vice versa.
160 // TestUIHandler is used for communication and test suceeds only when 169 // TestUIHandler is used for communication and test suceeds only when
161 // |TestUIHandler| sucessfully receives "ack" message from WebUI page. 170 // |TestUIHandler| sucessfully receives "ack" message from WebUI page.
162 #if TARGET_IPHONE_SIMULATOR 171 #if TARGET_IPHONE_SIMULATOR
163 #define MAYBE_MessageExchange MessageExchange 172 #define MAYBE_MessageExchange MessageExchange
164 #else 173 #else
165 #define MAYBE_MessageExchange FLAKY_MessageExchange 174 #define MAYBE_MessageExchange FLAKY_MessageExchange
166 #endif 175 #endif
167 // TODO(crbug.com/720098): Enable this test on device. 176 // TODO(crbug.com/720098): Enable this test on device.
168 TEST_F(WebUIMojoTest, MAYBE_MessageExchange) { 177 TEST_F(WebUIMojoTest, MAYBE_MessageExchange) {
169 web_state()->SetWebUsageEnabled(true); 178 @autoreleasepool {
170 web_state()->GetView(); // WebState won't load URL without view. 179 web_state()->SetWebUsageEnabled(true);
171 GURL url( 180 web_state()->GetView(); // WebState won't load URL without view.
172 url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0).Serialize()); 181 GURL url(url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0)
173 NavigationManager::WebLoadParams load_params(url); 182 .Serialize());
174 web_state()->GetNavigationManager()->LoadURLWithParams(load_params); 183 NavigationManager::WebLoadParams load_params(url);
184 web_state()->GetNavigationManager()->LoadURLWithParams(load_params);
175 185
176 // Wait until |TestUIHandler| receives "fin" message from WebUI page. 186 // Wait until |TestUIHandler| receives "fin" message from WebUI page.
177 bool fin_received = testing::WaitUntilConditionOrTimeout(kMessageTimeout, ^{ 187 bool fin_received = testing::WaitUntilConditionOrTimeout(kMessageTimeout, ^{
178 // Flush any pending tasks. Don't RunUntilIdle() because 188 // Flush any pending tasks. Don't RunUntilIdle() because
179 // RunUntilIdle() is incompatible with mojo::SimpleWatcher's 189 // RunUntilIdle() is incompatible with mojo::SimpleWatcher's
180 // automatic arming behavior, which Mojo JS still depends upon. 190 // automatic arming behavior, which Mojo JS still depends upon.
181 // 191 //
182 // TODO(crbug.com/701875): Introduce the full watcher API to JS and get rid 192 // TODO(crbug.com/701875): Introduce the full watcher API to JS and get
183 // of this hack. 193 // rid of this hack.
184 base::RunLoop loop; 194 base::RunLoop loop;
185 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 195 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
186 loop.QuitClosure()); 196 loop.QuitClosure());
187 loop.Run(); 197 loop.Run();
188 return test_ui_handler()->IsFinReceived(); 198 return test_ui_handler()->IsFinReceived();
189 }); 199 });
190 200
191 ASSERT_TRUE(fin_received); 201 ASSERT_TRUE(fin_received);
192 EXPECT_FALSE(web_state()->IsLoading()); 202 EXPECT_FALSE(web_state()->IsLoading());
193 EXPECT_EQ(url, web_state()->GetLastCommittedURL()); 203 EXPECT_EQ(url, web_state()->GetLastCommittedURL());
204 }
194 } 205 }
195 206
196 } // namespace web 207 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/web_state/wk_web_view_security_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698