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
3 // found in the LICENSE file.
5 #include "components/web_view/test_frame_tree_delegate.h"
7 #include "base/run_loop.h"
8 #include "components/web_view/client_initiated_frame_connection.h"
9 #include "components/web_view/frame_connection.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 TestFrameTreeDelegate::TestFrameTreeDelegate(mojo::ApplicationImpl
* app
)
16 waiting_for_create_frame_(false),
17 waiting_for_destroy_frame_(nullptr),
18 most_recent_frame_(nullptr),
19 waiting_for_frame_disconnected_(nullptr) {}
21 TestFrameTreeDelegate::~TestFrameTreeDelegate() {}
23 Frame
* TestFrameTreeDelegate::WaitForCreateFrame() {
25 ADD_FAILURE() << "already waiting";
28 waiting_for_create_frame_
= true;
29 run_loop_
.reset(new base::RunLoop
);
32 return most_recent_frame_
;
35 void TestFrameTreeDelegate::WaitForDestroyFrame(Frame
* frame
) {
36 ASSERT_FALSE(is_waiting());
37 waiting_for_destroy_frame_
= frame
;
38 run_loop_
.reset(new base::RunLoop
);
43 void TestFrameTreeDelegate::WaitForFrameDisconnected(Frame
* frame
) {
44 ASSERT_FALSE(is_waiting());
45 waiting_for_frame_disconnected_
= frame
;
46 run_loop_
.reset(new base::RunLoop
);
51 scoped_ptr
<FrameUserData
> TestFrameTreeDelegate::CreateUserDataForNewFrame(
52 mojom::FrameClientPtr frame_client
) {
53 return make_scoped_ptr(
54 new ClientInitiatedFrameConnection(frame_client
.Pass()));
57 bool TestFrameTreeDelegate::CanPostMessageEventToFrame(
60 mojom::HTMLMessageEvent
* event
) {
64 void TestFrameTreeDelegate::LoadingStateChanged(bool loading
, double progress
) {
67 void TestFrameTreeDelegate::TitleChanged(const mojo::String
& title
) {}
69 void TestFrameTreeDelegate::NavigateTopLevel(Frame
* source
,
70 mojo::URLRequestPtr request
) {}
72 void TestFrameTreeDelegate::CanNavigateFrame(
74 mojo::URLRequestPtr request
,
75 const CanNavigateFrameCallback
& callback
) {
76 FrameConnection::CreateConnectionForCanNavigateFrame(
77 app_
, target
, request
.Pass(), callback
);
80 void TestFrameTreeDelegate::DidStartNavigation(Frame
* frame
) {}
82 void TestFrameTreeDelegate::DidCommitProvisionalLoad(Frame
* frame
) {}
84 void TestFrameTreeDelegate::DidCreateFrame(Frame
* frame
) {
85 if (waiting_for_create_frame_
) {
86 most_recent_frame_
= frame
;
91 void TestFrameTreeDelegate::DidDestroyFrame(Frame
* frame
) {
92 if (waiting_for_destroy_frame_
== frame
) {
93 waiting_for_destroy_frame_
= nullptr;
98 void TestFrameTreeDelegate::OnViewEmbeddedInFrameDisconnected(Frame
* frame
) {
99 if (waiting_for_frame_disconnected_
== frame
) {
100 waiting_for_frame_disconnected_
= nullptr;
105 } // namespace web_view