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. 4 5 #include "chrome/browser/ui/webui/options/options_browsertest.h" 6 7 #include "base/bind.h" 8 #include "base/values.h" 9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "content/public/browser/navigation_controller.h" 12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_ui.h" 15 #include "url/gurl.h" 16 17 using content::NavigationController; 18 using content::NavigationEntry; 19 using content::WebUIMessageHandler; 20 21 OptionsBrowserTest::OptionsBrowserTest() { 22 } 23 24 OptionsBrowserTest::~OptionsBrowserTest() { 25 } 26 27 void OptionsBrowserTest::RegisterMessages() { 28 web_ui()->RegisterMessageCallback( 29 "optionsTestReportHistory", base::Bind(&OptionsBrowserTest::ReportHistory, 30 base::Unretained(this))); 31 } 32 33 // Includes the current entry. 34 void OptionsBrowserTest::ReportHistory(const base::ListValue* list_value) { 35 const NavigationController& controller = 36 browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 37 base::ListValue history; 38 const int current = controller.GetCurrentEntryIndex(); 39 for (int i = 0; i <= current; ++i) { 40 GURL url = controller.GetEntryAtIndex(i)->GetVirtualURL(); 41 history.Append(new base::StringValue(url.spec())); 42 } 43 web_ui()->CallJavascriptFunction( 44 "OptionsWebUINavigationTest.verifyHistoryCallback", history); 45 } 46 47 content::WebUIMessageHandler* OptionsBrowserTest::GetMockMessageHandler() { 48 return this; 49 } 50