1 // Copyright 2013 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 "chrome/browser/ui/webui/options/options_browsertest.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
19 using content::NavigationController
;
20 using content::NavigationEntry
;
21 using content::WebUIMessageHandler
;
23 OptionsBrowserTest::OptionsBrowserTest() {
26 OptionsBrowserTest::~OptionsBrowserTest() {
29 void OptionsBrowserTest::RegisterMessages() {
30 web_ui()->RegisterMessageCallback(
31 "optionsTestReportHistory", base::Bind(&OptionsBrowserTest::ReportHistory
,
32 base::Unretained(this)));
34 web_ui()->RegisterMessageCallback(
35 "optionsTestSetPref", base::Bind(&OptionsBrowserTest::HandleSetPref
,
36 base::Unretained(this)));
39 // Includes the current entry.
40 void OptionsBrowserTest::ReportHistory(const base::ListValue
* list_value
) {
41 const NavigationController
& controller
=
42 browser()->tab_strip_model()->GetActiveWebContents()->GetController();
43 base::ListValue history
;
44 const int current
= controller
.GetCurrentEntryIndex();
45 for (int i
= 0; i
<= current
; ++i
) {
46 GURL url
= controller
.GetEntryAtIndex(i
)->GetVirtualURL();
47 history
.Append(new base::StringValue(url
.spec()));
49 web_ui()->CallJavascriptFunction(
50 "OptionsWebUIExtendedTest.verifyHistoryCallback", history
);
53 void OptionsBrowserTest::ClearPref(const char* path
) {
54 browser()->profile()->GetPrefs()->ClearPref(path
);
57 void OptionsBrowserTest::HandleSetPref(const base::ListValue
* args
) {
58 ASSERT_EQ(2u, args
->GetSize());
60 std::string pref_name
;
61 ASSERT_TRUE(args
->GetString(0, &pref_name
));
62 const base::Value
* pref_value
;
63 ASSERT_TRUE(args
->Get(1, &pref_value
));
65 browser()->profile()->GetPrefs()->Set(pref_name
.c_str(), *pref_value
);
68 content::WebUIMessageHandler
* OptionsBrowserTest::GetMockMessageHandler() {