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 AddMessageHandler(WebUIMessageHandler
* handler
) override
;
41 void RegisterMessageCallback(const std::string
& message
,
42 const MessageCallback
& callback
) override
{}
43 void ProcessWebUIMessage(const GURL
& source_url
,
44 const std::string
& message
,
45 const base::ListValue
& args
) override
{}
46 void CallJavascriptFunction(const std::string
& function_name
) override
;
47 void CallJavascriptFunction(const std::string
& function_name
,
48 const base::Value
& arg1
) override
;
49 void CallJavascriptFunction(const std::string
& function_name
,
50 const base::Value
& arg1
,
51 const base::Value
& arg2
) override
;
52 void CallJavascriptFunction(const std::string
& function_name
,
53 const base::Value
& arg1
,
54 const base::Value
& arg2
,
55 const base::Value
& arg3
) override
;
56 void CallJavascriptFunction(const std::string
& function_name
,
57 const base::Value
& arg1
,
58 const base::Value
& arg2
,
59 const base::Value
& arg3
,
60 const base::Value
& arg4
) override
;
61 void CallJavascriptFunction(
62 const std::string
& function_name
,
63 const std::vector
<const base::Value
*>& args
) override
;
67 explicit CallData(const std::string
& function_name
);
70 void TakeAsArg1(base::Value
* arg
);
71 void TakeAsArg2(base::Value
* arg
);
73 const std::string
& function_name() const { return function_name_
; }
74 const base::Value
* arg1() const { return arg1_
.get(); }
75 const base::Value
* arg2() const { return arg2_
.get(); }
78 std::string function_name_
;
79 scoped_ptr
<base::Value
> arg1_
;
80 scoped_ptr
<base::Value
> arg2_
;
83 const ScopedVector
<CallData
>& call_data() const { return call_data_
; }
86 ScopedVector
<CallData
> call_data_
;
87 ScopedVector
<WebUIMessageHandler
> handlers_
;
88 base::string16 temp_string_
;
89 WebContents
* web_contents_
;
92 } // namespace content
94 #endif // CONTENT_PUBLIC_TEST_TEST_WEB_UI_H_