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

Side by Side Diff: components/web_view/frame_apptest.cc

Issue 1391963004: Correctly record and pass around navigation start time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « components/web_view/frame.cc ('k') | components/web_view/frame_tree.h » ('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 #include "components/web_view/frame.h" 5 #include "components/web_view/frame.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/time/time.h"
13 #include "components/mus/public/cpp/view_observer.h" 14 #include "components/mus/public/cpp/view_observer.h"
14 #include "components/mus/public/cpp/view_tree_connection.h" 15 #include "components/mus/public/cpp/view_tree_connection.h"
15 #include "components/mus/public/cpp/view_tree_delegate.h" 16 #include "components/mus/public/cpp/view_tree_delegate.h"
16 #include "components/mus/public/cpp/view_tree_host_factory.h" 17 #include "components/mus/public/cpp/view_tree_host_factory.h"
17 #include "components/web_view/frame.h" 18 #include "components/web_view/frame.h"
18 #include "components/web_view/frame_connection.h" 19 #include "components/web_view/frame_connection.h"
19 #include "components/web_view/frame_tree.h" 20 #include "components/web_view/frame_tree.h"
20 #include "components/web_view/frame_tree_delegate.h" 21 #include "components/web_view/frame_tree_delegate.h"
21 #include "components/web_view/frame_user_data.h" 22 #include "components/web_view/frame_user_data.h"
22 #include "components/web_view/test_frame_tree_delegate.h" 23 #include "components/web_view/test_frame_tree_delegate.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void last_loading_state_changed_notification(uint32_t* frame_id, 118 void last_loading_state_changed_notification(uint32_t* frame_id,
118 bool* loading) const { 119 bool* loading) const {
119 *frame_id = last_loading_state_changed_notification_.frame_id; 120 *frame_id = last_loading_state_changed_notification_.frame_id;
120 *loading = last_loading_state_changed_notification_.loading; 121 *loading = last_loading_state_changed_notification_.loading;
121 } 122 }
122 123
123 uint32_t last_dispatch_load_event_frame_id() const { 124 uint32_t last_dispatch_load_event_frame_id() const {
124 return last_dispatch_load_event_frame_id_; 125 return last_dispatch_load_event_frame_id_;
125 } 126 }
126 127
128 base::TimeTicks last_navigation_start_time() const {
129 return last_navigation_start_time_;
130 }
131
127 // mojom::FrameClient: 132 // mojom::FrameClient:
128 void OnConnect(mojom::FramePtr frame, 133 void OnConnect(mojom::FramePtr frame,
129 uint32_t change_id, 134 uint32_t change_id,
130 uint32_t view_id, 135 uint32_t view_id,
131 mojom::ViewConnectType view_connect_type, 136 mojom::ViewConnectType view_connect_type,
132 mojo::Array<mojom::FrameDataPtr> frames, 137 mojo::Array<mojom::FrameDataPtr> frames,
138 int64_t navigation_start_time_ticks,
133 const OnConnectCallback& callback) override { 139 const OnConnectCallback& callback) override {
134 connect_count_++; 140 connect_count_++;
135 connect_frames_ = frames.Pass(); 141 connect_frames_ = frames.Pass();
136 if (frame) 142 if (frame)
137 server_frame_ = frame.Pass(); 143 server_frame_ = frame.Pass();
138 callback.Run(); 144 callback.Run();
139 if (!on_connect_callback_.is_null()) 145 if (!on_connect_callback_.is_null())
140 on_connect_callback_.Run(); 146 on_connect_callback_.Run();
147
148 last_navigation_start_time_ =
149 base::TimeTicks::FromInternalValue(navigation_start_time_ticks);
141 } 150 }
142 void OnFrameAdded(uint32_t change_id, mojom::FrameDataPtr frame) override { 151 void OnFrameAdded(uint32_t change_id, mojom::FrameDataPtr frame) override {
143 adds_.push_back(frame.Pass()); 152 adds_.push_back(frame.Pass());
144 } 153 }
145 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {} 154 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {}
146 void OnFrameClientPropertyChanged(uint32_t frame_id, 155 void OnFrameClientPropertyChanged(uint32_t frame_id,
147 const mojo::String& name, 156 const mojo::String& name,
148 mojo::Array<uint8_t> new_data) override {} 157 mojo::Array<uint8_t> new_data) override {}
149 void OnPostMessageEvent(uint32_t source_frame_id, 158 void OnPostMessageEvent(uint32_t source_frame_id,
150 uint32_t target_frame_id, 159 uint32_t target_frame_id,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 198
190 int connect_count_; 199 int connect_count_;
191 mojo::Array<mojom::FrameDataPtr> connect_frames_; 200 mojo::Array<mojom::FrameDataPtr> connect_frames_;
192 mojom::FramePtr server_frame_; 201 mojom::FramePtr server_frame_;
193 mojo::Array<mojom::FrameDataPtr> adds_; 202 mojo::Array<mojom::FrameDataPtr> adds_;
194 base::Closure on_connect_callback_; 203 base::Closure on_connect_callback_;
195 base::Closure on_loading_state_changed_callback_; 204 base::Closure on_loading_state_changed_callback_;
196 base::Closure on_dispatch_load_event_callback_; 205 base::Closure on_dispatch_load_event_callback_;
197 LoadingStateChangedNotification last_loading_state_changed_notification_; 206 LoadingStateChangedNotification last_loading_state_changed_notification_;
198 uint32_t last_dispatch_load_event_frame_id_; 207 uint32_t last_dispatch_load_event_frame_id_;
208 base::TimeTicks last_navigation_start_time_;
199 209
200 DISALLOW_COPY_AND_ASSIGN(TestFrameClient); 210 DISALLOW_COPY_AND_ASSIGN(TestFrameClient);
201 }; 211 };
202 212
203 class FrameTest; 213 class FrameTest;
204 214
205 // ViewAndFrame maintains the View and TestFrameClient associated with 215 // ViewAndFrame maintains the View and TestFrameClient associated with
206 // a single FrameClient. In other words this maintains the data structures 216 // a single FrameClient. In other words this maintains the data structures
207 // needed to represent a client side frame. To obtain one use 217 // needed to represent a client side frame. To obtain one use
208 // FrameTest::WaitForViewAndFrame(). 218 // FrameTest::WaitForViewAndFrame().
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 295 }
286 296
287 protected: 297 protected:
288 ViewTreeConnection* window_manager() { return window_manager_; } 298 ViewTreeConnection* window_manager() { return window_manager_; }
289 TestFrameTreeDelegate* frame_tree_delegate() { 299 TestFrameTreeDelegate* frame_tree_delegate() {
290 return frame_tree_delegate_.get(); 300 return frame_tree_delegate_.get();
291 } 301 }
292 FrameTree* frame_tree() { return frame_tree_.get(); } 302 FrameTree* frame_tree() { return frame_tree_.get(); }
293 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } 303 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); }
294 304
295 scoped_ptr<ViewAndFrame> NavigateFrame(ViewAndFrame* view_and_frame) { 305 scoped_ptr<ViewAndFrame> NavigateFrameWithStartTime(
306 ViewAndFrame* view_and_frame,
307 base::TimeTicks navigation_start_time) {
296 mojo::URLRequestPtr request(mojo::URLRequest::New()); 308 mojo::URLRequestPtr request(mojo::URLRequest::New());
297 request->url = mojo::String::From(application_impl()->url()); 309 request->url = mojo::String::From(application_impl()->url());
310 request->originating_time_ticks = navigation_start_time.ToInternalValue();
298 view_and_frame->server_frame()->RequestNavigate( 311 view_and_frame->server_frame()->RequestNavigate(
299 mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, 312 mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME,
300 view_and_frame->view()->id(), request.Pass()); 313 view_and_frame->view()->id(), request.Pass());
301 return WaitForViewAndFrame(); 314 return WaitForViewAndFrame();
302 } 315 }
303 316
317 scoped_ptr<ViewAndFrame> NavigateFrame(ViewAndFrame* view_and_frame) {
318 return NavigateFrameWithStartTime(view_and_frame, base::TimeTicks());
319 }
320
304 // Creates a new shared frame as a child of |parent|. 321 // Creates a new shared frame as a child of |parent|.
305 scoped_ptr<ViewAndFrame> CreateChildViewAndFrame(ViewAndFrame* parent) { 322 scoped_ptr<ViewAndFrame> CreateChildViewAndFrame(ViewAndFrame* parent) {
306 mus::View* child_frame_view = parent->view()->connection()->CreateView(); 323 mus::View* child_frame_view = parent->view()->connection()->CreateView();
307 parent->view()->AddChild(child_frame_view); 324 parent->view()->AddChild(child_frame_view);
308 325
309 scoped_ptr<ViewAndFrame> view_and_frame(new ViewAndFrame); 326 scoped_ptr<ViewAndFrame> view_and_frame(new ViewAndFrame);
310 view_and_frame->set_view(child_frame_view); 327 view_and_frame->set_view(child_frame_view);
311 328
312 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; 329 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties;
313 client_properties.mark_non_null(); 330 client_properties.mark_non_null();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // Creates a FrameTree, which creates a single frame. Wait for the 376 // Creates a FrameTree, which creates a single frame. Wait for the
360 // FrameClient to be connected to. 377 // FrameClient to be connected to.
361 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); 378 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl()));
362 scoped_ptr<FrameConnection> frame_connection = 379 scoped_ptr<FrameConnection> frame_connection =
363 CreateFrameConnection(application_impl()); 380 CreateFrameConnection(application_impl());
364 mojom::FrameClient* frame_client = frame_connection->frame_client(); 381 mojom::FrameClient* frame_client = frame_connection->frame_client();
365 mojo::ViewTreeClientPtr view_tree_client = 382 mojo::ViewTreeClientPtr view_tree_client =
366 frame_connection->GetViewTreeClient(); 383 frame_connection->GetViewTreeClient();
367 mus::View* frame_root_view = window_manager()->CreateView(); 384 mus::View* frame_root_view = window_manager()->CreateView();
368 window_manager()->GetRoot()->AddChild(frame_root_view); 385 window_manager()->GetRoot()->AddChild(frame_root_view);
369 frame_tree_.reset( 386 frame_tree_.reset(new FrameTree(
370 new FrameTree(0u, frame_root_view, view_tree_client.Pass(), 387 0u, frame_root_view, view_tree_client.Pass(),
371 frame_tree_delegate_.get(), frame_client, 388 frame_tree_delegate_.get(), frame_client, frame_connection.Pass(),
372 frame_connection.Pass(), Frame::ClientPropertyMap())); 389 Frame::ClientPropertyMap(), base::TimeTicks::Now()));
373 root_view_and_frame_ = WaitForViewAndFrame(); 390 root_view_and_frame_ = WaitForViewAndFrame();
374 } 391 }
375 392
376 // Overridden from testing::Test: 393 // Overridden from testing::Test:
377 void TearDown() override { 394 void TearDown() override {
378 root_view_and_frame_.reset(); 395 root_view_and_frame_.reset();
379 frame_tree_.reset(); 396 frame_tree_.reset();
380 frame_tree_delegate_.reset(); 397 frame_tree_delegate_.reset();
381 ApplicationTestBase::TearDown(); 398 ApplicationTestBase::TearDown();
382 } 399 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 545
529 child_view_and_frame->server_frame()->DispatchLoadEventToParent(); 546 child_view_and_frame->server_frame()->DispatchLoadEventToParent();
530 547
531 run_loop.Run(); 548 run_loop.Run();
532 549
533 uint32_t frame_id = root_view_and_frame() 550 uint32_t frame_id = root_view_and_frame()
534 ->test_frame_client() 551 ->test_frame_client()
535 ->last_dispatch_load_event_frame_id(); 552 ->last_dispatch_load_event_frame_id();
536 EXPECT_EQ(child_frame_id, frame_id); 553 EXPECT_EQ(child_frame_id, frame_id);
537 } 554 }
555
556 TEST_F(FrameTest, PassAlongNavigationStartTime) {
557 scoped_ptr<ViewAndFrame> child_view_and_frame(
558 CreateChildViewAndFrame(root_view_and_frame()));
559 ASSERT_TRUE(child_view_and_frame);
560
561 base::TimeTicks navigation_start_time = base::TimeTicks::FromInternalValue(1);
562 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame =
563 NavigateFrameWithStartTime(child_view_and_frame.get(),
564 navigation_start_time)
565 .Pass();
566 EXPECT_EQ(navigation_start_time,
567 navigated_child_view_and_frame->test_frame_client()
568 ->last_navigation_start_time());
569 }
570
538 } // namespace web_view 571 } // namespace web_view
OLDNEW
« no previous file with comments | « components/web_view/frame.cc ('k') | components/web_view/frame_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698