summaryrefslogtreecommitdiffstats
path: root/content/public/test/test_web_ui.cc
blob: 03c4d7bd376d02391af6bc14219c29db416475a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/logging.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "content/public/test/test_web_ui.h"

namespace content {

TestWebUI::TestWebUI() : web_contents_(nullptr) {
}

TestWebUI::~TestWebUI() {
  ClearTrackedCalls();
}

void TestWebUI::ClearTrackedCalls() {
  call_data_.clear();
}

WebContents* TestWebUI::GetWebContents() const {
  return web_contents_;
}

WebUIController* TestWebUI::GetController() const {
  return nullptr;
}

float TestWebUI::GetDeviceScaleFactor() const {
  return 1.0f;
}

const base::string16& TestWebUI::GetOverriddenTitle() const {
  return temp_string_;
}

ui::PageTransition TestWebUI::GetLinkTransitionType() const {
  return ui::PAGE_TRANSITION_LINK;
}

int TestWebUI::GetBindings() const {
  return 0;
}

bool TestWebUI::HasRenderFrame() {
  return false;
}

void TestWebUI::AddMessageHandler(WebUIMessageHandler* handler) {
  handlers_.push_back(handler);
}

void TestWebUI::CallJavascriptFunction(const std::string& function_name) {
  call_data_.push_back(new CallData(function_name));
}

void TestWebUI::CallJavascriptFunction(const std::string& function_name,
                                       const base::Value& arg1) {
  call_data_.push_back(new CallData(function_name));
  call_data_.back()->TakeAsArg1(arg1.DeepCopy());
}

void TestWebUI::CallJavascriptFunction(const std::string& function_name,
                                       const base::Value& arg1,
                                       const base::Value& arg2) {
  call_data_.push_back(new CallData(function_name));
  call_data_.back()->TakeAsArg1(arg1.DeepCopy());
  call_data_.back()->TakeAsArg2(arg2.DeepCopy());
}

void TestWebUI::CallJavascriptFunction(const std::string& function_name,
                                       const base::Value& arg1,
                                       const base::Value& arg2,
                                       const base::Value& arg3) {
  call_data_.push_back(new CallData(function_name));
  call_data_.back()->TakeAsArg1(arg1.DeepCopy());
  call_data_.back()->TakeAsArg2(arg2.DeepCopy());
  call_data_.back()->TakeAsArg3(arg3.DeepCopy());
}

void TestWebUI::CallJavascriptFunction(const std::string& function_name,
                                       const base::Value& arg1,
                                       const base::Value& arg2,
                                       const base::Value& arg3,
                                       const base::Value& arg4) {
  NOTREACHED();
}

void TestWebUI::CallJavascriptFunction(
    const std::string& function_name,
    const std::vector<const base::Value*>& args) {
  NOTREACHED();
}

TestWebUI::CallData::CallData(const std::string& function_name)
    : function_name_(function_name) {
}

TestWebUI::CallData::~CallData() {
}

void TestWebUI::CallData::TakeAsArg1(base::Value* arg) {
  arg1_.reset(arg);
}

void TestWebUI::CallData::TakeAsArg2(base::Value* arg) {
  arg2_.reset(arg);
}

void TestWebUI::CallData::TakeAsArg3(base::Value* arg) {
  arg3_.reset(arg);
}

}  // namespace content