diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 00:27:01 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 00:27:01 +0000 |
commit | 7dad3d5f3d40d86158ed96536fd681701b43611d (patch) | |
tree | ec2dd5d5a9a836eb1244d6b9e1d36a6518a15f17 | |
parent | f661899570cea4abb593ea7d6d8143afe0c7f8b8 (diff) | |
download | chromium_src-7dad3d5f3d40d86158ed96536fd681701b43611d.zip chromium_src-7dad3d5f3d40d86158ed96536fd681701b43611d.tar.gz chromium_src-7dad3d5f3d40d86158ed96536fd681701b43611d.tar.bz2 |
Test cookie prompting.
Adds automation plumbing to support changing the content settings.
This change also fixes WaitForNavigation to watch for the LOAD_STOP event
instead of the NAV_ENTRY_COMMITTED event. This better matches the intent (I
think) of the automation interface, and it also matches the similar function
defined in ui_test_utils (used by browser tests). This also better matches the
NavigationNotificationObserver, which seems desirable given the implementation
of AutomationProvider::WaitForNavigation.
It turns out that only one UI test was using WaitForNavigation, and I confirmed
that it still functions properly.
This change also modifies the NavigationNotificationObserver to allow it to
watch for the current page load to complete. Normally, it waits for the first
LOAD_START or NAV_ENTRY_COMMITTED event to switch into the mode where it
watches for LOAD_STOP. However, that makes it not so useful for
WaitForNavigation, which is intended to be called after triggering the start of
a new navigation.
This change also makes it so that the cookie prompt supports the automation
message box 'OK' and 'Cancel' buttons, so that we can remotely press those
buttons.
Leveraging all of these changes enables some basic cookie prompting tests to be
written.
I had to modify browser_frame_win.cc to ensure that BrowserList::SetLastActive
is called even while running under remote desktop.
R=phajdan.jr@chromium.org
BUG=37182
TEST=cookie_modal_dialog_uitest.cc
Review URL: http://codereview.chromium.org/661102
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40575 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 238 insertions, 49 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index d0cb97e..85a8e0b 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -42,6 +42,7 @@ #include "chrome/browser/find_bar.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/find_notification_details.h" +#include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/login_prompt.h" @@ -192,10 +193,11 @@ void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { NotificationObserver* AutomationProvider::AddNavigationStatusListener( NavigationController* tab, IPC::Message* reply_message, - int number_of_navigations) { + int number_of_navigations, bool include_current_navigation) { NotificationObserver* observer = new NavigationNotificationObserver(tab, this, reply_message, - number_of_navigations); + number_of_navigations, + include_current_navigation); notification_observer_list_.AddObserver(observer); return observer; @@ -469,6 +471,7 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { #if defined(OS_WIN) IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved) #endif + IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting) IPC_END_MESSAGE_MAP() } @@ -529,7 +532,8 @@ void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete( Browser* browser = FindAndActivateTab(tab); if (browser) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations); + AddNavigationStatusListener(tab, reply_message, number_of_navigations, + false); // TODO(darin): avoid conversion to GURL browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); @@ -567,7 +571,7 @@ void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); browser->GoBack(CURRENT_TAB); return; } @@ -583,7 +587,7 @@ void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); browser->GoForward(CURRENT_TAB); return; } @@ -599,7 +603,7 @@ void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); browser->Reload(); return; } @@ -623,7 +627,7 @@ void AutomationProvider::SetAuth(int tab_handle, // not strictly correct, because a navigation can require both proxy and // server auth, but it should be OK for now. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); handler->SetAuth(username, password); return; } @@ -643,7 +647,7 @@ void AutomationProvider::CancelAuth(int tab_handle, if (iter != login_handler_map_.end()) { // If auth is needed again after this, something is screwy. LoginHandler* handler = iter->second; - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); handler->CancelAuth(); return; } @@ -1437,7 +1441,7 @@ void AutomationProvider::ShowInterstitialPage(int tab_handle, NavigationController* controller = tab_tracker_->GetResource(tab_handle); TabContents* tab_contents = controller->tab_contents(); - AddNavigationStatusListener(controller, reply_message, 1); + AddNavigationStatusListener(controller, reply_message, 1, false); AutomationInterstitialPage* interstitial = new AutomationInterstitialPage(tab_contents, GURL("about:interstitial"), @@ -1586,7 +1590,7 @@ void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, InterstitialPage::GetInterstitialPage(tab_contents); if (ssl_blocking_page) { if (proceed) { - AddNavigationStatusListener(tab, reply_message, 1); + AddNavigationStatusListener(tab, reply_message, 1, false); ssl_blocking_page->Proceed(); return; } @@ -1872,7 +1876,7 @@ void AutomationProvider::ClickInfoBarAccept(int handle, int count = nav_controller->tab_contents()->infobar_delegate_count(); if (info_bar_index >= 0 && info_bar_index < count) { if (wait_for_navigation) { - AddNavigationStatusListener(nav_controller, reply_message, 1); + AddNavigationStatusListener(nav_controller, reply_message, 1, false); } InfoBarDelegate* delegate = nav_controller->tab_contents()->GetInfoBarDelegateAt( @@ -1914,7 +1918,7 @@ void AutomationProvider::WaitForNavigation(int handle, return; } - AddNavigationStatusListener(controller, reply_message, 1); + AddNavigationStatusListener(controller, reply_message, 1, true); } void AutomationProvider::SetIntPreference(int handle, @@ -2148,7 +2152,8 @@ void AutomationProvider::GoBackBlockUntilNavigationsComplete( NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations); + AddNavigationStatusListener(tab, reply_message, number_of_navigations, + false); browser->GoBack(CURRENT_TAB); return; } @@ -2165,7 +2170,8 @@ void AutomationProvider::GoForwardBlockUntilNavigationsComplete( NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = FindAndActivateTab(tab); if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { - AddNavigationStatusListener(tab, reply_message, number_of_navigations); + AddNavigationStatusListener(tab, reply_message, number_of_navigations, + false); browser->GoForward(CURRENT_TAB); return; } @@ -2267,3 +2273,23 @@ void AutomationProvider::SaveAsAsync(int tab_handle) { if (tab_contents) tab_contents->OnSavePage(); } + +void AutomationProvider::SetContentSetting( + int handle, + const std::string& host, + ContentSettingsType content_type, + ContentSetting setting, + bool* success) { + *success = false; + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + HostContentSettingsMap* map = + browser->profile()->GetHostContentSettingsMap(); + if (host.empty()) { + map->SetDefaultContentSetting(content_type, setting); + } else { + map->SetContentSetting(host, content_type, setting); + } + *success = true; + } +} diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 24b381a..02b695e 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -25,6 +25,7 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/history/history.h" #include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/common/content_settings.h" #include "chrome/common/notification_registrar.h" #include "chrome/test/automation/automation_constants.h" #include "ipc/ipc_message.h" @@ -77,7 +78,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, // RemoveNavigationStatusListener method. NotificationObserver* AddNavigationStatusListener( NavigationController* tab, IPC::Message* reply_message, - int number_of_navigations); + int number_of_navigations, bool include_current_navigation); void RemoveNavigationStatusListener(NotificationObserver* obs); @@ -232,6 +233,11 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, #if defined(OS_WIN) void OnBrowserMoved(int handle); #endif + void SetContentSetting(int handle, + const std::string& host, + ContentSettingsType content_type, + ContentSetting setting, + bool* success); #if defined(OS_WIN) void ScheduleMouseEvent(views::View* view, diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index dfea17c..63fcb22 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -118,7 +118,8 @@ NavigationNotificationObserver::NavigationNotificationObserver( NavigationController* controller, AutomationProvider* automation, IPC::Message* reply_message, - int number_of_navigations) + int number_of_navigations, + bool include_current_navigation) : automation_(automation), reply_message_(reply_message), controller_(controller), @@ -131,6 +132,9 @@ NavigationNotificationObserver::NavigationNotificationObserver( registrar_.Add(this, NotificationType::LOAD_STOP, source); registrar_.Add(this, NotificationType::AUTH_NEEDED, source); registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source); + + if (include_current_navigation && controller->tab_contents()->is_loading()) + navigation_started_ = true; } NavigationNotificationObserver::~NavigationNotificationObserver() { @@ -241,7 +245,8 @@ void TabAppendedNotificationObserver::ObserveTab( return; } - automation_->AddNavigationStatusListener(controller, reply_message_, 1); + automation_->AddNavigationStatusListener(controller, reply_message_, 1, + false); } TabClosedNotificationObserver::TabClosedNotificationObserver( @@ -447,6 +452,7 @@ void AppModalDialogShownObserver::Observe( NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::APP_MODAL_DIALOG_SHOWN); + AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( reply_message_, true); automation_->Send(reply_message_); @@ -506,7 +512,7 @@ bool ExecuteBrowserCommandObserver::CreateAndRegisterObserver( case IDC_RELOAD: { automation->AddNavigationStatusListener( &browser->GetSelectedTabContents()->controller(), - reply_message, 1); + reply_message, 1, false); break; } default: { diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 58409d0..d5411e5 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -91,7 +91,8 @@ class NavigationNotificationObserver : public NotificationObserver { NavigationNotificationObserver(NavigationController* controller, AutomationProvider* automation, IPC::Message* reply_message, - int number_of_navigations); + int number_of_navigations, + bool include_current_navigation); ~NavigationNotificationObserver(); virtual void Observe(NotificationType type, diff --git a/chrome/browser/automation/automation_tab_tracker.h b/chrome/browser/automation/automation_tab_tracker.h index 36c2bb9d..02b40be 100644 --- a/chrome/browser/automation/automation_tab_tracker.h +++ b/chrome/browser/automation/automation_tab_tracker.h @@ -31,7 +31,7 @@ class AutomationTabTracker Source<NavigationController>(resource)); // We also want to know about navigations so we can keep track of the last // navigation time. - registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, + registrar_.Add(this, NotificationType::LOAD_STOP, Source<NavigationController>(resource)); } @@ -40,7 +40,7 @@ class AutomationTabTracker Source<NavigationController>(resource)); registrar_.Remove(this, NotificationType::EXTERNAL_TAB_CLOSED, Source<NavigationController>(resource)); - registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, + registrar_.Remove(this, NotificationType::LOAD_STOP, Source<NavigationController>(resource)); } @@ -48,7 +48,7 @@ class AutomationTabTracker const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::NAV_ENTRY_COMMITTED: + case NotificationType::LOAD_STOP: last_navigation_times_[Source<NavigationController>(source).ptr()] = base::Time::Now(); return; diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc index e655d3a..abf84fd 100644 --- a/chrome/browser/cookie_modal_dialog.cc +++ b/chrome/browser/cookie_modal_dialog.cc @@ -4,6 +4,7 @@ #include "chrome/browser/cookie_modal_dialog.h" +#include "app/message_box_flags.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -106,3 +107,9 @@ void CookiePromptModalDialog::BlockSiteData(bool remember) { void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false); } + +int CookiePromptModalDialog::GetDialogButtons() { + // Enable the automation interface to accept/dismiss this dialog. + return MessageBoxFlags::DIALOGBUTTON_OK | + MessageBoxFlags::DIALOGBUTTON_CANCEL; +} diff --git a/chrome/browser/cookie_modal_dialog_gtk.cc b/chrome/browser/cookie_modal_dialog_gtk.cc index 3fcf37b..c33f85b 100644 --- a/chrome/browser/cookie_modal_dialog_gtk.cc +++ b/chrome/browser/cookie_modal_dialog_gtk.cc @@ -27,10 +27,6 @@ void CookiePromptModalDialog::CreateAndShowDialog() { gtk_widget_set_size_request(dialog_, width, -1); } -int CookiePromptModalDialog::GetDialogButtons() { - return 0; -} - void CookiePromptModalDialog::AcceptWindow() { HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); } diff --git a/chrome/browser/cookie_modal_dialog_mac.mm b/chrome/browser/cookie_modal_dialog_mac.mm index 29ca336..e80c2d6 100644 --- a/chrome/browser/cookie_modal_dialog_mac.mm +++ b/chrome/browser/cookie_modal_dialog_mac.mm @@ -124,10 +124,6 @@ void CookiePromptModalDialog::CreateAndShowDialog() { } // The functions below are used by the automation framework. -int CookiePromptModalDialog::GetDialogButtons() { - NOTIMPLEMENTED(); - return 0; -} void CookiePromptModalDialog::AcceptWindow() { NOTIMPLEMENTED(); diff --git a/chrome/browser/cookie_modal_dialog_uitest.cc b/chrome/browser/cookie_modal_dialog_uitest.cc new file mode 100644 index 0000000..75f39a7 --- /dev/null +++ b/chrome/browser/cookie_modal_dialog_uitest.cc @@ -0,0 +1,66 @@ +// 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. + +#include "chrome/browser/net/url_request_mock_http_job.h" +#include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/ui/ui_test.h" + +class CookieModalDialogTest : public UITest { + public: + void RunBasicTest(MessageBoxFlags::DialogButton button_to_press, + const std::wstring& expected_title) { + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser); + + ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_ASK)); + + GURL url(URLRequestMockHTTPJob::GetMockUrl( + FilePath(FILE_PATH_LITERAL("cookie2.html")))); + + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); + ASSERT_TRUE(tab_proxy); + + int64 last_navigation_time; + ASSERT_TRUE(tab_proxy->GetLastNavigationTime(&last_navigation_time)); + ASSERT_TRUE(tab_proxy->NavigateToURLAsync(url)); + + // cookie2.html sets a cookie and then reads back the cookie within onload, + // which means that the navigation will not complete until the cookie + // prompt is dismissed. + + bool modal_dialog_showing = false; + MessageBoxFlags::DialogButton available_buttons; + ASSERT_TRUE(automation()->WaitForAppModalDialog( + command_execution_timeout_ms())); + ASSERT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, + &available_buttons)); + ASSERT_TRUE(modal_dialog_showing); + ASSERT_NE((button_to_press & available_buttons), 0); + ASSERT_TRUE(automation()->ClickAppModalDialogButton(button_to_press)); + + // Now, the cookie prompt is dismissed, and we can wait for the navigation + // to complete. Before returning from onload, the test updates the title. + // We can therefore be sure that upon return from WaitForNavigation that + // the title has been updated with the final test result. + + ASSERT_TRUE(tab_proxy->WaitForNavigation(last_navigation_time)); + + std::wstring title; + ASSERT_TRUE(tab_proxy->GetTabTitle(&title)); + + EXPECT_EQ(expected_title, title); + } +}; + +// TODO(port): Enable these once the cookie dialogs are fully implemented. +#if defined(OS_WIN) +TEST_F(CookieModalDialogTest, AllowCookies) { + RunBasicTest(MessageBoxFlags::DIALOGBUTTON_OK, L"cookie allowed"); +} + +TEST_F(CookieModalDialogTest, BlockCookies) { + RunBasicTest(MessageBoxFlags::DIALOGBUTTON_CANCEL, L"cookie blocked"); +} +#endif diff --git a/chrome/browser/cookie_modal_dialog_views.cc b/chrome/browser/cookie_modal_dialog_views.cc index 8fb7f99..94c3f6f 100644 --- a/chrome/browser/cookie_modal_dialog_views.cc +++ b/chrome/browser/cookie_modal_dialog_views.cc @@ -12,14 +12,6 @@ // TODO(zelidrag): Make this work on Linux (views). -int CookiePromptModalDialog::GetDialogButtons() { -#if defined(OS_WIN) - return dialog_->GetDialogButtons(); -#else - return 0; -#endif -} - void CookiePromptModalDialog::AcceptWindow() { #if defined(OS_WIN) views::DialogClientView* client_view = diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc index 2c01525..fa0bbe6 100644 --- a/chrome/browser/views/cookie_prompt_view.cc +++ b/chrome/browser/views/cookie_prompt_view.cc @@ -102,6 +102,12 @@ views::View* CookiePromptView::GetContentsView() { return this; } +bool CookiePromptView::Accept() { + parent_->AllowSiteData(remember_radio_->checked(), session_expire_); + signaled_ = true; + return true; +} + // CookieInfoViewDelegate overrides: void CookiePromptView::ModifyExpireDate(bool session_expire) { session_expire_ = session_expire; @@ -114,8 +120,7 @@ void CookiePromptView::ModifyExpireDate(bool session_expire) { void CookiePromptView::ButtonPressed(views::Button* sender, const views::Event& event) { if (sender == allow_button_) { - parent_->AllowSiteData(remember_radio_->checked(), session_expire_); - signaled_ = true; + Accept(); GetWindow()->Close(); } else if (sender == block_button_) { parent_->BlockSiteData(remember_radio_->checked()); diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h index 101895e..0d9567e 100644 --- a/chrome/browser/views/cookie_prompt_view.h +++ b/chrome/browser/views/cookie_prompt_view.h @@ -61,6 +61,7 @@ class CookiePromptView : public views::View, virtual void WindowClosing(); virtual views::View* GetContentsView(); virtual bool IsModal() const { return true; } + virtual bool Accept(); // views::ButtonListener overrides. virtual void ButtonPressed(views::Button* sender, const views::Event& event); diff --git a/chrome/browser/views/frame/browser_frame_win.cc b/chrome/browser/views/frame/browser_frame_win.cc index ddfe7ba..8c51c8a 100644 --- a/chrome/browser/views/frame/browser_frame_win.cc +++ b/chrome/browser/views/frame/browser_frame_win.cc @@ -234,6 +234,18 @@ int BrowserFrameWin::GetShowState() const { return browser_view_->GetShowState(); } +void BrowserFrameWin::Activate() { + // When running under remote desktop, if the remote desktop client is not + // active on the users desktop, then none of the windows contained in the + // remote desktop will be activated. However, WindowWin::Activate will still + // bring this browser window to the foreground. We explicitly set ourselves + // as the last active browser window to ensure that we get treated as such by + // the rest of Chrome. + BrowserList::SetLastActive(browser_view_->browser()); + + WindowWin::Activate(); +} + views::NonClientFrameView* BrowserFrameWin::CreateFrameViewForWindow() { if (AlwaysUseNativeFrame()) browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_); diff --git a/chrome/browser/views/frame/browser_frame_win.h b/chrome/browser/views/frame/browser_frame_win.h index daf0f2b..d446eb7 100644 --- a/chrome/browser/views/frame/browser_frame_win.h +++ b/chrome/browser/views/frame/browser_frame_win.h @@ -67,6 +67,7 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { // Overridden from views::Window: virtual int GetShowState() const; + virtual void Activate(); virtual bool IsAppWindow() const { return true; } virtual views::NonClientFrameView* CreateFrameViewForWindow(); virtual void UpdateFrameAfterFrameChange(); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 4d8d675..7b7c95c 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -271,6 +271,7 @@ 'app/chrome_main_uitest.cc', 'browser/browser_encoding_uitest.cc', 'browser/browser_uitest.cc', + 'browser/cookie_modal_dialog_uitest.cc', 'browser/dom_ui/new_tab_ui_uitest.cc', 'browser/download/download_uitest.cc', 'browser/download/save_page_uitest.cc', diff --git a/chrome/common/common_param_traits.cc b/chrome/common/common_param_traits.cc index 62e57ff..d767aef 100644 --- a/chrome/common/common_param_traits.cc +++ b/chrome/common/common_param_traits.cc @@ -181,20 +181,15 @@ void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::wstring* l) { void ParamTraits<ContentSettings>::Write( Message* m, const ContentSettings& settings) { - for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) - WriteParam(m, static_cast<int>(settings.settings[i])); + for (size_t i = 0; i < arraysize(settings.settings); ++i) + WriteParam(m, settings.settings[i]); } bool ParamTraits<ContentSettings>::Read( const Message* m, void** iter, ContentSettings* r) { - for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - int local_setting; - if (!m->ReadInt(iter, &local_setting)) + for (size_t i = 0; i < arraysize(r->settings); ++i) { + if (!ReadParam(m, iter, &r->settings[i])) return false; - if (local_setting < 0 || - local_setting >= static_cast<int>(CONTENT_SETTING_NUM_SETTINGS)) - return false; - r->settings[i] = static_cast<ContentSetting>(local_setting); } return true; } diff --git a/chrome/common/common_param_traits.h b/chrome/common/common_param_traits.h index 99b1896..72b92c8 100644 --- a/chrome/common/common_param_traits.h +++ b/chrome/common/common_param_traits.h @@ -90,6 +90,26 @@ struct ParamTraits<gfx::Size> { }; template <> +struct ParamTraits<ContentSetting> { + typedef ContentSetting param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p)); + } + static bool Read(const Message* m, void** iter, param_type* r) { + int value; + if (!ReadParam(m, iter, &value)) + return false; + if (value < 0 || value >= static_cast<int>(CONTENT_SETTING_NUM_SETTINGS)) + return false; + *r = static_cast<param_type>(value); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + LogParam(static_cast<int>(p), l); + } +}; + +template <> struct ParamTraits<ContentSettingsType> { typedef ContentSettingsType param_type; static void Write(Message* m, const param_type& p) { diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index ae68136..29bd287 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -15,6 +15,7 @@ #include "base/gfx/point.h" #include "base/gfx/rect.h" #include "base/string16.h" +#include "chrome/common/content_settings.h" #include "chrome/common/navigation_types.h" #include "chrome/test/automation/autocomplete_edit_proxy.h" #include "googleurl/src/gurl.h" @@ -1212,4 +1213,13 @@ IPC_BEGIN_MESSAGES(Automation) std::string /* cookies */, int /* opaque_cookie_id */) + // If the given host is empty, then the default content settings are + // modified. + IPC_SYNC_MESSAGE_ROUTED4_1(AutomationMsg_SetContentSetting, + int /* browser handle */, + std::string /* host */, + ContentSettingsType /* content type */, + ContentSetting /* setting */, + bool /* success */) + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc index 7ecb9d9..2b62b71 100644 --- a/chrome/test/automation/browser_proxy.cc +++ b/chrome/test/automation/browser_proxy.cc @@ -395,6 +395,25 @@ bool BrowserProxy::SetBooleanPreference(const std::wstring& name, return result; } +bool BrowserProxy::SetDefaultContentSetting(ContentSettingsType content_type, + ContentSetting setting) { + return SetContentSetting(std::string(), content_type, setting); +} + +bool BrowserProxy::SetContentSetting(const std::string& host, + ContentSettingsType content_type, + ContentSetting setting) { + if (!is_valid()) + return false; + + bool result = false; + + sender_->Send(new AutomationMsg_SetContentSetting(0, handle_, host, + content_type, setting, + &result)); + return result; +} + bool BrowserProxy::TerminateSession() { if (!is_valid()) return false; diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h index 76de8f0..939e87b 100644 --- a/chrome/test/automation/browser_proxy.h +++ b/chrome/test/automation/browser_proxy.h @@ -14,6 +14,7 @@ #include <string> #include "chrome/browser/browser.h" +#include "chrome/common/content_settings.h" #include "chrome/test/automation/automation_handle_tracker.h" class GURL; @@ -200,6 +201,15 @@ class BrowserProxy : public AutomationResourceProxy { // Sets the boolean value of the specified preference. bool SetBooleanPreference(const std::wstring& name, bool value); + // Sets default content settings. + bool SetDefaultContentSetting(ContentSettingsType content_type, + ContentSetting setting); + + // Sets content settings for a particular host (overriding the default). + bool SetContentSetting(const std::string& host, + ContentSettingsType content_type, + ContentSetting setting); + // Simulates a termination the browser session (as if the user logged off the // mahine). bool TerminateSession(); diff --git a/chrome/test/data/cookie2.html b/chrome/test/data/cookie2.html new file mode 100644 index 0000000..aa13434 --- /dev/null +++ b/chrome/test/data/cookie2.html @@ -0,0 +1,19 @@ +<html> +<head> +<script> +function setCookie() { + document.cookie = 'foo=baz'; + + // If there is a cookie prompt showing, then reading from document.cookie + // should block until the dialog is closed. + if (document.cookie.indexOf('foo') == -1) { + document.title = 'cookie blocked'; + } else { + document.title = 'cookie allowed'; + } +} +</script> +</head> +<body onload="setCookie();"> +</body> +</html> |