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 #ifndef CONTENT_PUBLIC_TEST_TEST_WEB_UI_H_
6 #define CONTENT_PUBLIC_TEST_TEST_WEB_UI_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/values.h"
13 #include "content/public/browser/web_ui.h"
17 // Test instance of WebUI that tracks the data passed to
18 // CallJavascriptFunction().
19 class TestWebUI
: public WebUI
{
22 ~TestWebUI() override
;
24 void ClearTrackedCalls();
25 void set_web_contents(WebContents
* web_contents
) {
26 web_contents_
= web_contents
;
30 WebContents
* GetWebContents() const override
;
31 WebUIController
* GetController() const override
;
32 void SetController(WebUIController
* controller
) override
{}
33 float GetDeviceScaleFactor() const override
;
34 const base::string16
& GetOverriddenTitle() const override
;
35 void OverrideTitle(const base::string16
& title
) override
{}
36 ui::PageTransition
GetLinkTransitionType() const override
;
37 void SetLinkTransitionType(ui::PageTransition type
) override
{}
38 int GetBindings() const override
;
39 void SetBindings(int bindings
) override
{}
40 void OverrideJavaScriptFrame(const std::string
& frame_name
) override
{}
41 void AddMessageHandler(WebUIMessageHandler
* handler
) override
;
42 void RegisterMessageCallback(const std::string
& message
,
43 const MessageCallback
& callback
) override
{}
44 void ProcessWebUIMessage(const GURL
& source_url
,
45 const std::string
& message
,
46 const base::ListValue
& args
) override
{}
47 void CallJavascriptFunction(const std::string
& function_name
) override
;
48 void CallJavascriptFunction(const std::string
& function_name
,
49 const base::Value
& arg1
) override
;
50 void CallJavascriptFunction(const std::string
& function_name
,
51 const base::Value
& arg1
,
52 const base::Value
& arg2
) override
;
53 void CallJavascriptFunction(const std::string
& function_name
,
54 const base::Value
& arg1
,
55 const base::Value
& arg2
,
56 const base::Value
& arg3
) override
;
57 void CallJavascriptFunction(const std::string
& function_name
,
58 const base::Value
& arg1
,
59 const base::Value
& arg2
,
60 const base::Value
& arg3
,
61 const base::Value
& arg4
) override
;
62 void CallJavascriptFunction(
63 const std::string
& function_name
,
64 const std::vector
<const base::Value
*>& args
) override
;
68 explicit CallData(const std::string
& function_name
);
71 void TakeAsArg1(base::Value
* arg
);
72 void TakeAsArg2(base::Value
* arg
);
74 const std::string
& function_name() const { return function_name_
; }
75 const base::Value
* arg1() const { return arg1_
.get(); }
76 const base::Value
* arg2() const { return arg2_
.get(); }
79 std::string function_name_
;
80 scoped_ptr
<base::Value
> arg1_
;
81 scoped_ptr
<base::Value
> arg2_
;
84 const ScopedVector
<CallData
>& call_data() const { return call_data_
; }
87 ScopedVector
<CallData
> call_data_
;
88 ScopedVector
<WebUIMessageHandler
> handlers_
;
89 base::string16 temp_string_
;
90 WebContents
* web_contents_
;
93 } // namespace content
95 #endif // CONTENT_PUBLIC_TEST_TEST_WEB_UI_H_