diff options
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 53 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 7 | ||||
-rw-r--r-- | chrome/test/functional/ssl.py | 39 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 34 |
4 files changed, 133 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 87578db..e2f5d12 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -82,6 +82,7 @@ #include "chrome/browser/ssl/ssl_manager.h" #include "chrome/browser/ssl/ssl_blocking_page.h" #include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/translate/translate_infobar_delegate.h" @@ -748,6 +749,56 @@ void AutomationProvider::GetBrowserInfo(Browser* browser, AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); } +// Sample json input: { "command": "GetNavigationInfo" } +// Refer to GetNavigationInfo() in chrome/test/pyautolib/pyauto.py for +// sample json output. +void AutomationProvider::GetNavigationInfo(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message) { + AutomationJSONReply reply(this, reply_message); + int tab_index; + TabContents* tab_contents = NULL; + if (!args->GetInteger("tab_index", &tab_index) || + !(tab_contents = browser->GetTabContentsAt(tab_index))) { + reply.SendError("tab_index missing or invalid."); + return; + } + scoped_ptr<DictionaryValue> return_value(new DictionaryValue); + const NavigationController& controller = tab_contents->controller(); + NavigationEntry* nav_entry = controller.GetActiveEntry(); + DCHECK(nav_entry); + + // Security info. + DictionaryValue* ssl = new DictionaryValue; + std::map<SecurityStyle, std::string> style_to_string; + style_to_string[SECURITY_STYLE_UNKNOWN] = "SECURITY_STYLE_UNKNOWN"; + style_to_string[SECURITY_STYLE_UNAUTHENTICATED] = + "SECURITY_STYLE_UNAUTHENTICATED"; + style_to_string[SECURITY_STYLE_AUTHENTICATION_BROKEN] = + "SECURITY_STYLE_AUTHENTICATION_BROKEN"; + style_to_string[SECURITY_STYLE_AUTHENTICATED] = + "SECURITY_STYLE_AUTHENTICATED"; + + NavigationEntry::SSLStatus ssl_status = nav_entry->ssl(); + ssl->SetString("security_style", + style_to_string[ssl_status.security_style()]); + ssl->SetBoolean("ran_insecure_content", ssl_status.ran_insecure_content()); + ssl->SetBoolean("displayed_insecure_content", + ssl_status.displayed_insecure_content()); + return_value->Set("ssl", ssl); + + // Page type. + std::map<NavigationEntry::PageType, std::string> pagetype_to_string; + pagetype_to_string[NavigationEntry::NORMAL_PAGE] = "NORMAL_PAGE"; + pagetype_to_string[NavigationEntry::ERROR_PAGE] = "ERROR_PAGE"; + pagetype_to_string[NavigationEntry::INTERSTITIAL_PAGE] = "INTERSTITIAL_PAGE"; + return_value->SetString("page_type", + pagetype_to_string[nav_entry->page_type()]); + + return_value->SetString("favicon_url", nav_entry->favicon().url().spec()); + reply.SendSuccess(return_value.get()); +} + // Sample json input: { "command": "GetHistoryInfo", // "search_text": "some text" } // Refer chrome/test/pyautolib/history_info.py for sample json output. @@ -2100,6 +2151,8 @@ void AutomationProvider::SendJSONRequest(int handle, handler_map["GetBrowserInfo"] = &AutomationProvider::GetBrowserInfo; + handler_map["GetNavigationInfo"] = &AutomationProvider::GetNavigationInfo; + handler_map["PerformActionOnInfobar"] = &AutomationProvider::PerformActionOnInfobar; diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index ff859591..00cc478 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -246,6 +246,13 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DictionaryValue* args, IPC::Message* reply_message); + // Get info about the state of navigation in a given tab. + // This includes ssl info. + // Uses the JSON interface for input/output. + void GetNavigationInfo(Browser* browser, + DictionaryValue* args, + IPC::Message* reply_message); + // Get info about downloads. This includes only ones that have been // registered by the history system. // Uses the JSON interface for input/output. diff --git a/chrome/test/functional/ssl.py b/chrome/test/functional/ssl.py new file mode 100644 index 0000000..1dcb8fb --- /dev/null +++ b/chrome/test/functional/ssl.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# Copyright (c) 2010 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. + +import os + +import pyauto_functional # Must be imported before pyauto +import pyauto + + +class SSLTest(pyauto.PyUITest): + """TestCase for SSL.""" + + def Debug(self): + """Test method for experimentation. + + This method will not run automatically. + Use: python chrome/test/functional/ssl.py ssl.SSLTest.Debug + """ + import pprint + pp = pprint.PrettyPrinter(indent=2) + while True: + raw_input('Hit <enter> to dump info.. ') + info = self.GetNavigationInfo() + pp.pprint(info) + + def testSSLPageBasic(self): + """Verify the navigation state in an https page.""" + self.NavigateToURL('https://www.google.com') + ssl = self.GetNavigationInfo()['ssl'] + security_style = ssl['security_style'] + self.assertEqual('SECURITY_STYLE_AUTHENTICATED', security_style) + self.assertFalse(ssl['displayed_insecure_content']) + self.assertFalse(ssl['ran_insecure_content']) + + +if __name__ == '__main__': + pyauto_functional.Main() diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 0d4f667..3677851 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -728,6 +728,40 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): } return self._GetResultFromJSONRequest(cmd_dict) + def GetNavigationInfo(self, tab_index=0, windex=0): + """Get info about the navigation state of a given tab. + + Args: + tab_index: The tab index, default is 0. + window_index: The window index, default is 0. + + Returns: + a dictionary. + Sample: + + { u'favicon_url': u'https://www.google.com/favicon.ico', + u'page_type': u'NORMAL_PAGE', + u'ssl': { u'displayed_insecure_content': False, + u'ran_insecure_content': False, + u'security_style': u'SECURITY_STYLE_AUTHENTICATED'}} + + Values for security_style can be: + SECURITY_STYLE_UNKNOWN + SECURITY_STYLE_UNAUTHENTICATED + SECURITY_STYLE_AUTHENTICATION_BROKEN + SECURITY_STYLE_AUTHENTICATED + + Values for page_type can be: + NORMAL_PAGE + ERROR_PAGE + INTERSTITIAL_PAGE + """ + cmd_dict = { # Prepare command for the json interface + 'command': 'GetNavigationInfo', + 'tab_index': tab_index, + } + return self._GetResultFromJSONRequest(cmd_dict, windex=windex) + def GetHistoryInfo(self, search_text=''): """Return info about browsing history. |