Chromium Code Reviews| Index: chrome/browser/notifications/notification_browsertest.cc |
| diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc |
| index 3a693da62ab1bc75aa4622195efb5b80c72b9247..3b47c2f2e47c6372298d57623036796adce4eded 100644 |
| --- a/chrome/browser/notifications/notification_browsertest.cc |
| +++ b/chrome/browser/notifications/notification_browsertest.cc |
| @@ -2,25 +2,652 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| +#include "chrome/browser/api/infobars/infobar_delegate.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/infobars/infobar_tab_helper.h" |
| +#include "chrome/browser/notifications/balloon.h" |
| +#include "chrome/browser/notifications/balloon_collection.h" |
| +#include "chrome/browser/notifications/balloon_host.h" |
| +#include "chrome/browser/notifications/desktop_notification_service.h" |
| +#include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| +#include "chrome/browser/notifications/notification.h" |
| +#include "chrome/browser/notifications/notification_ui_manager.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/sessions/session_tab_helper.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/navigation_controller.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_types.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/browser_test_utils.h" |
| +#include "googleurl/src/gurl.h" |
| #include "net/base/net_util.h" |
| #include "net/test/test_server.h" |
| +#include "webkit/glue/window_open_disposition.h" |
| -class NotificationsPermissionTest : public InProcessBrowserTest { |
| +#if defined(OS_WIN) |
| +#include "base/win/windows_version.h" |
| +#endif |
| + |
| +class NotificationsPermissionTest : public InProcessBrowserTest, |
| + public content::NotificationObserver { |
| public: |
| - NotificationsPermissionTest() {} |
| + NotificationsPermissionTest(); |
| + |
| + protected: |
| + // InProcessBrowserTest |
|
kkania
2012/11/13 23:38:21
The preferred style is:
Overriden from InProcessBr
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; |
| + |
| + // content::NotificationObserver |
|
kkania
2012/11/13 23:38:21
same here
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
|
kkania
2012/11/13 23:38:21
for chromium, we usually encourage you to include
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + |
| + DesktopNotificationService* GetDesktopNotificationService(); |
| + const std::deque<Balloon*>& GetActiveBalloons(); |
| + |
| + bool CloseNotificationAndWait(const Notification& notification); |
| + bool WaitForInfoBarCount(Browser* browser, |
| + const size_t count, |
|
kkania
2012/11/13 23:38:21
don't put const for primitives
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + const int index, |
| + bool increasing); |
| + bool CheckNotificationCount(const size_t count); |
| + Browser* CreateBrowserWindow(Browser* source_browser, bool is_incognito); |
| + void CloseBrowserWindow(Browser* browser); |
| + void CloseTab(Browser* browser, const int index); |
| + void CrashTab(Browser* browser, const int index); |
| + void CrashNotification(Balloon* balloon); |
| + |
| + void Debug(); |
|
kkania
2012/11/13 23:38:21
remove?
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + |
| + void SetDefaultPermissionSetting(ContentSetting setting); |
| + ContentSetting GetDefaultPermissionSetting(); |
| + void GetDeniedOrigins(ContentSettingsForOneType* settings); |
| + void GetAllowedOrigins(ContentSettingsForOneType* settings); |
| + void SetDeniedOrigins(const std::vector<GURL>& new_origins); |
| + void SetAllowedOrigins(const std::vector<GURL>& new_origins); |
| + void DenyOrigin(const GURL& origin); |
| + void AllowOrigin(const GURL& origin); |
| + void DropOriginPreference(const GURL& origin); |
| + void AllowAllOrigins(); |
| + |
| + void VerifyInfobar(const Browser* browser, |
| + const std::string& origin, |
| + const int index); |
| + std::string CreateNotification(Browser* browser, |
| + const bool waiting, |
|
kkania
2012/11/13 23:38:21
indent is wrong here
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + const std::string& icon, |
| + const std::string& title, |
| + const std::string& body, |
| + const std::string& replace_id); |
| + std::string CreateSimpleNotification(Browser* browser, const bool waiting); |
| + std::string CreateHTMLNotification(const std::string& content_url, |
| + Browser* browser, |
| + const std::string& replace_id, |
| + bool wait_for_display); |
| + void RequestPermission(Browser* browser); |
| + void CancelNotification(const std::string& notification_id, Browser* browser); |
| + bool PerformActionOnInfobar(Browser* browser, |
| + const std::string action, |
| + const int infobar_index, |
| + const int tab_index); |
| + bool checkOriginInSetting(const ContentSettingsForOneType & settings, |
| + const GURL & origin); |
| + |
| + static const ContentSetting kAllowAllSetting; |
| + static const ContentSetting kDenyAllSetting; |
| + GURL EMPTY_PAGE_URL; |
| + GURL TEST_PAGE_URL; |
| + |
| + private: |
| + size_t target_infobar_count_; |
| + size_t target_balloon_count_; |
| + static const std::string kReference; |
|
kkania
2012/11/13 23:38:21
http://google-styleguide.googlecode.com/svn/trunk/
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + |
| + void GetPrefsByContentSetting(ContentSetting setting, |
| + ContentSettingsForOneType* settings); |
| + void PrintSettings(const ContentSettingsForOneType & settings, |
| + const std::string & message); |
| + |
| + class BrowserOpenedNotificationObserver : |
|
kkania
2012/11/13 23:38:21
move this class out. put it in an unnamed namespac
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + public content::NotificationObserver { |
| + public: |
| + BrowserOpenedNotificationObserver(); |
|
kkania
2012/11/13 23:38:21
indent is wrong
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + virtual ~BrowserOpenedNotificationObserver(); |
| + |
| + void Wait(); |
| + Browser* new_browser() { return new_browser_; } |
| + |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + private: |
| + content::NotificationRegistrar registrar_; |
| + Browser* new_browser_; |
| + int new_window_id_; |
| + bool done_; |
| + bool running_; |
| + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver); |
| + }; |
| }; |
| -// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. |
| -IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { |
| +NotificationsPermissionTest::BrowserOpenedNotificationObserver |
| +::BrowserOpenedNotificationObserver() |
| + : new_browser_(NULL), |
| + new_window_id_(-1), |
| + done_(false), |
| + running_(false) { |
| + registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| + registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| + content::NotificationService::AllBrowserContextsAndSources()); |
| +} |
| + |
| +NotificationsPermissionTest::BrowserOpenedNotificationObserver |
| +::~BrowserOpenedNotificationObserver() {} |
| + |
| +void NotificationsPermissionTest::BrowserOpenedNotificationObserver::Wait() { |
| + if (done_) |
| + return; |
| + |
| + running_ = true; |
| + message_loop_runner_ = new content::MessageLoopRunner; |
| + message_loop_runner_->Run(); |
| + EXPECT_TRUE(done_); |
| +} |
| + |
| +void NotificationsPermissionTest::BrowserOpenedNotificationObserver |
| + ::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_BROWSER_OPENED) { |
| + // Store the new browser ID and continue waiting for a new tab within it |
| + // to stop loading. |
| + new_browser_ = content::Source<Browser>(source).ptr(); |
| + new_window_id_ = new_browser_->session_id().id(); |
| + } else { |
| + DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type); |
| + content::NavigationController* controller = |
| + content::Source<content::NavigationController>(source).ptr(); |
| + SessionTabHelper* session_tab_helper = |
| + SessionTabHelper::FromWebContents(controller->GetWebContents()); |
| + int window_id = session_tab_helper ? session_tab_helper->window_id().id() |
| + : -1; |
| + if (window_id == new_window_id_) { |
| + registrar_.RemoveAll(); |
| + done_ = true; |
| + if (!running_) |
| + return; |
| + |
| + message_loop_runner_->Quit(); |
| + running_ = false; |
| + } |
| + } |
| +} |
| + |
| +const ContentSetting NotificationsPermissionTest::kAllowAllSetting |
| + = CONTENT_SETTING_ALLOW; |
| + |
| +const ContentSetting NotificationsPermissionTest::kDenyAllSetting |
| + = CONTENT_SETTING_BLOCK; |
| + |
| +const std::string NotificationsPermissionTest::kReference = "preference"; |
| + |
| +NotificationsPermissionTest::NotificationsPermissionTest() |
| + : target_infobar_count_(0U), |
| + target_balloon_count_(0U) { |
| +} |
| + |
| +void NotificationsPermissionTest::SetUpInProcessBrowserTestFixture() { |
| + InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| + |
| ASSERT_TRUE(test_server()->Start()); |
| + EMPTY_PAGE_URL = test_server()->GetURL("files/empty.html"); |
| + TEST_PAGE_URL = test_server()->GetURL( |
| + "files/notifications/notification_tester.html"); |
| +} |
| + |
| +void NotificationsPermissionTest::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_BROWSER_CLOSED: { |
| + LOG(ERROR) << "Got NOTIFICATION_BROWSER_CLOSED notification"; |
| + MessageLoopForUI::current()->Quit(); |
| + break; |
| + } |
| + case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: |
| + case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { |
| + const InfoBarTabHelper* infoBarTabHelper = |
| + content::Source<const InfoBarTabHelper>(source).ptr(); |
| + if (infoBarTabHelper->GetInfoBarCount() == target_infobar_count_) { |
| + target_infobar_count_ = 0U; |
| + MessageLoopForUI::current()->Quit(); |
| + } |
| + break; |
| + } |
| + case chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED: |
| + case chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED: { |
| + size_t current_balloon_count = GetActiveBalloons().size(); |
| + LOG(ERROR) << "Got NOTIFICATION_NOTIFY_BALLOON_CONNECTED notification. " |
| + << "Number of desktop notification: " |
| + << current_balloon_count; |
| + if (current_balloon_count == target_balloon_count_) { |
| + target_balloon_count_ = 0U; |
| + MessageLoopForUI::current()->Quit(); |
| + } |
| + break; |
| + } |
| + default: |
| + break; |
| + } |
| +} |
| + |
| +DesktopNotificationService* |
| + NotificationsPermissionTest::GetDesktopNotificationService() { |
| + Profile* profile = browser()->profile(); |
| + return DesktopNotificationServiceFactory::GetForProfile(profile); |
| +} |
| + |
| +const std::deque<Balloon*>& NotificationsPermissionTest::GetActiveBalloons() { |
| + NotificationUIManager* manager = g_browser_process->notification_ui_manager(); |
| + return manager->balloon_collection()->GetActiveBalloons(); |
| +} |
| + |
| +bool NotificationsPermissionTest::CloseNotificationAndWait( |
| + const Notification& notification) { |
| + LOG(ERROR) << "CLOSE AND WAIT"; |
| + content::WindowedNotificationObserver signal( |
| + chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, |
| + content::NotificationService::AllSources()); |
| + NotificationUIManager* manager = g_browser_process->notification_ui_manager(); |
| + LOG(ERROR) << "CLOSE"; |
| + bool flag = manager->CancelById(notification.notification_id()); |
| + signal.Wait(); |
| + LOG(ERROR) << "DONE WAITING"; |
| + return flag; |
| +} |
| + |
| +bool NotificationsPermissionTest::WaitForInfoBarCount( |
| + Browser* browser, |
| + const size_t count, |
| + const int index, |
| + bool increasing) { |
| + size_t current_count = InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount(); |
| + if (count != current_count) { |
| + target_infobar_count_ = count; |
| + ui_test_utils::RegisterAndWait( |
| + this, |
| + increasing ? chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED |
| + : chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| + content::NotificationService::AllSources()); |
| + } |
| + |
| + current_count = InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount(); |
| + return count == current_count; |
| +} |
| + |
| +bool NotificationsPermissionTest::CheckNotificationCount(const size_t count) { |
| + NotificationUIManager* manager = g_browser_process->notification_ui_manager(); |
| + return count == manager->balloon_collection()->GetActiveBalloons().size(); |
| +} |
| + |
| +Browser* NotificationsPermissionTest::CreateBrowserWindow( |
| + Browser* source_browser, |
| + bool is_incognito) { |
| + BrowserOpenedNotificationObserver signal; |
|
kkania
2012/11/13 23:38:21
We should be able to do something like:
ui_test_u
chrisgao (Use stgao instead)
2012/11/14 21:38:28
I have tried the following three ways to create an
|
| + if (is_incognito) |
| + chrome::ExecuteCommand(source_browser, IDC_NEW_INCOGNITO_WINDOW); |
| + else |
| + chrome::ExecuteCommand(source_browser, IDC_NEW_WINDOW); |
| + signal.Wait(); |
| + return signal.new_browser(); |
| +} |
| + |
| +void NotificationsPermissionTest::CloseBrowserWindow(Browser* browser) { |
| + content::WindowedNotificationObserver signal( |
|
kkania
2012/11/13 23:38:21
rename all instances of signal to observer; that f
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + chrome::NOTIFICATION_BROWSER_CLOSED, |
| + content::Source<Browser>(browser)); |
| + browser->window()->Close(); |
| + signal.Wait(); |
| +} |
| + |
| +void NotificationsPermissionTest::CloseTab(Browser* browser, const int index) { |
|
kkania
2012/11/13 23:38:21
You only use this func in one place, so remove thi
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + content::WindowedNotificationObserver signal( |
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| + content::NotificationService::AllSources()); |
| + chrome::CloseWebContents(browser, chrome::GetWebContentsAt(browser, index)); |
| + signal.Wait(); |
| +} |
| + |
| +void NotificationsPermissionTest::CrashTab(Browser* browser, const int index) { |
| + content::CrashTab(chrome::GetWebContentsAt(browser, index)); |
| +} |
| + |
| +void NotificationsPermissionTest::CrashNotification(Balloon* balloon) { |
| + content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); |
| +} |
| + |
| +void NotificationsPermissionTest::Debug() { |
| + ContentSetting defaultSetting = GetDefaultPermissionSetting(); |
| + LOG(INFO) << "DefaultContentSetting:" << defaultSetting; |
| + ContentSettingsForOneType settings; |
| + // allowed |
| + GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, &settings); |
| + PrintSettings(settings, "Allowed origins"); |
| + // denied |
| + GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); |
| + PrintSettings(settings, "Denied origins"); |
| +} |
| + |
| +bool NotificationsPermissionTest::checkOriginInSetting( |
|
kkania
2012/11/13 23:38:21
Check
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + const ContentSettingsForOneType & settings, |
| + const GURL & origin) { |
| + ContentSettingsPattern pattern = ContentSettingsPattern::FromURLNoWildcard( |
| + origin); |
| + for (ContentSettingsForOneType::const_iterator it = settings.begin(); |
| + it != settings.end(); ++it) { |
| + if (it->primary_pattern == pattern) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +void NotificationsPermissionTest::SetDefaultPermissionSetting( |
| + ContentSetting setting) { |
| + DesktopNotificationService* service = GetDesktopNotificationService(); |
| + service->SetDefaultContentSetting(setting); |
| +} |
| + |
| +ContentSetting NotificationsPermissionTest::GetDefaultPermissionSetting() { |
| + DesktopNotificationService* service = GetDesktopNotificationService(); |
| + return service->GetDefaultContentSetting(NULL); |
| +} |
| + |
| +void NotificationsPermissionTest::GetDeniedOrigins( |
| + ContentSettingsForOneType* settings) { |
| + GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, settings); |
| +} |
| + |
| +void NotificationsPermissionTest::GetAllowedOrigins( |
| + ContentSettingsForOneType* settings) { |
| + GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, settings); |
| +} |
| + |
| +void NotificationsPermissionTest::SetDeniedOrigins( |
| + const std::vector<GURL>& new_origins) { |
| + // clear original denied origin list |
| + ContentSettingsForOneType old_origins; |
| + GetDeniedOrigins(&old_origins); |
| + for (ContentSettingsForOneType::const_iterator it = old_origins.begin(); |
| + it != old_origins.end(); ++it) { |
| + GetDesktopNotificationService()->ClearSetting(it->primary_pattern); |
| + } |
| + // set new origins |
| + for (std::vector<GURL>::const_iterator it = new_origins.begin(); |
| + it != new_origins.end(); ++it) { |
| + DenyOrigin(*it); |
| + } |
| +} |
| +void NotificationsPermissionTest::SetAllowedOrigins( |
| + const std::vector<GURL>& new_origins) { |
| + // clear original allowed origin list |
| + ContentSettingsForOneType old_origins; |
| + GetAllowedOrigins(&old_origins); |
| + for (ContentSettingsForOneType::const_iterator it = old_origins.begin(); |
| + it != old_origins.end(); ++it) { |
| + GetDesktopNotificationService()->ClearSetting(it->primary_pattern); |
| + } |
| + // set new origins |
| + for (std::vector<GURL>::const_iterator it = new_origins.begin(); |
| + it != new_origins.end(); ++it) { |
| + AllowOrigin(*it); |
| + } |
| +} |
| +void NotificationsPermissionTest::DenyOrigin(const GURL& origin) { |
| + DropOriginPreference(origin); |
| + GetDesktopNotificationService()->DenyPermission(origin); |
| +} |
| +void NotificationsPermissionTest::AllowOrigin(const GURL& origin) { |
| + DropOriginPreference(origin); |
| + GetDesktopNotificationService()->GrantPermission(origin); |
| +} |
| +void NotificationsPermissionTest::DropOriginPreference(const GURL& origin) { |
| + GetDesktopNotificationService()->ClearSetting( |
| + ContentSettingsPattern::FromURLNoWildcard(origin)); |
| +} |
| +void NotificationsPermissionTest::AllowAllOrigins() { |
| + GetDesktopNotificationService()->ResetAllOrigins(); |
| + GetDesktopNotificationService()->SetDefaultContentSetting( |
| + CONTENT_SETTING_ALLOW); |
| +} |
| + |
| +void NotificationsPermissionTest::VerifyInfobar( |
| + const Browser* browser, |
| + const std::string& origin, |
| + const int index) { |
| + InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser, index)); |
|
kkania
2012/11/13 23:38:21
indent
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + |
| + ASSERT_EQ(1U, infobar_helper->GetInfoBarCount()); |
| + InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(0); |
| + ASSERT_TRUE(infobar->AsConfirmInfoBarDelegate()); |
| + ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); |
| + int buttons = confirm_infobar->GetButtons(); |
| + if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { |
| + EXPECT_EQ( |
| + ASCIIToUTF16("Allow"), |
| + confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| + } else { |
| + EXPECT_TRUE(false); |
| + } |
| + if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| + EXPECT_EQ( |
| + ASCIIToUTF16("Deny"), |
| + confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| + } else { |
| + EXPECT_TRUE(false); |
| + } |
| + std::string text("Allow "); |
| + text.append(origin); |
| + text.append(" to show desktop notifications?"); |
| + EXPECT_EQ(UTF8ToUTF16(text), confirm_infobar->GetMessageText()); |
| +} |
| + |
| +std::string NotificationsPermissionTest::CreateNotification( |
| + Browser* browser, |
| + const bool waiting, |
| + const std::string& icon, |
| + const std::string& title, |
| + const std::string& body, |
| + const std::string& replace_id) { |
| + std::string result; |
| + |
| + std::string script("createNotification("); |
|
kkania
2012/11/13 23:38:21
use base::StringPrintf
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + script += "'" + icon + "'"; |
| + script += ",'" + title + "'"; |
| + script += ",'" + body + "'"; |
| + if (replace_id.length() > 0) { |
| + script += ",'" + replace_id + "'"; |
| + } |
| + script += ");"; |
| + |
| + std::wstring tmp(script.length(), L' '); |
| + UTF8ToWide(script.c_str(), script.length(), &tmp); |
| + |
| + bool flag = false; |
| + if (!waiting) { |
| + flag = content::ExecuteJavaScriptAndExtractString( |
| + chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| + L"", |
| + tmp, |
| + &result); |
| + } else { |
| + LOG(ERROR) << "Create and Wait"; |
|
kkania
2012/11/13 23:38:21
remove all logs
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + content::WindowedNotificationObserver signal( |
| + chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, |
| + content::NotificationService::AllSources()); |
| + flag = content::ExecuteJavaScriptAndExtractString( |
| + chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| + L"", |
| + tmp, |
| + &result); |
| + signal.Wait(); |
| + LOG(ERROR) << "Done Wait"; |
| + } |
| + EXPECT_TRUE(flag); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + return result; |
| +} |
| + |
| +std::string NotificationsPermissionTest::CreateSimpleNotification( |
| + Browser* browser, const bool waiting) { |
| + return CreateNotification( |
| + browser, |
| + waiting, |
| + "no_such_file.png", |
| + "My Title", |
| + "My Body", |
| + ""); |
| +} |
| +std::string NotificationsPermissionTest::CreateHTMLNotification( |
| + const std::string& content_url, |
| + Browser* browser, |
| + const std::string& replace_id, |
| + bool wait_for_display) { |
| + std::string result; |
| + |
| + std::string script( |
| + "window.domAutomationController.send(createHTMLNotification("); |
| + script += "'" + content_url + "'"; |
| + script += ",'" + replace_id + "'"; |
| + if (wait_for_display) { |
| + script += ", true"; |
| + } else { |
| + script += ", false"; |
| + } |
| + script += "));"; |
| + |
| + std::wstring tmp(script.length(), L' '); |
| + UTF8ToWide(script.c_str(), script.length(), &tmp); |
| + |
| + bool flag = content::ExecuteJavaScriptAndExtractString( |
| + chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| + L"", |
| + tmp, |
| + &result); |
| + EXPECT_TRUE(flag); |
| + |
| + return result; |
| +} |
| + |
| +void NotificationsPermissionTest::RequestPermission(Browser* browser) { |
|
kkania
2012/11/13 23:38:21
return bool here and ASSERT_TRUE in the tests, so
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + std::string result; |
| + ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| + chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| + L"", |
| + L"requestPermission();", |
| + &result)); |
| + EXPECT_EQ(result, "1"); |
| +} |
| + |
| +void NotificationsPermissionTest::CancelNotification( |
| + const std::string& notification_id, |
| + Browser* browser) { |
| + std::string script("cancelNotification("); |
|
kkania
2012/11/13 23:38:21
base::StringPrintf
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + script += "'" + notification_id + "'"; |
| + script += ");"; |
| + |
| + std::wstring tmp(script.length(), L' '); |
| + UTF8ToWide(script.c_str(), script.length(), &tmp); |
|
kkania
2012/11/13 23:38:21
I think there's a version of UTF8ToWide that takes
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + |
| + std::string result; |
| + ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| + chrome::GetActiveWebContents(browser)->GetRenderViewHost(), |
| + L"", |
| + tmp, |
| + &result)); |
| + EXPECT_EQ(result, "1"); |
| +} |
| + |
| +bool NotificationsPermissionTest::PerformActionOnInfobar( |
|
kkania
2012/11/13 23:38:21
Change this to separate allow, deny, and dismiss f
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Changed to enum.
On 2012/11/13 23:38:21, kkania w
|
| + Browser* browser, |
| + const std::string action, |
| + const int infobar_index, |
| + const int tab_index) { |
| + InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser, tab_index)); |
| + |
| + InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt( |
| + infobar_index); |
| + if ("Dismiss" == action) { |
| + infobar->InfoBarDismissed(); |
| + infobar_helper->RemoveInfoBar(infobar); |
| + return true; |
| + } else if ("Allow" == action) { |
| + ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate(); |
| + if (confirm_bar->Accept()) { |
| + infobar_helper->RemoveInfoBar(infobar); |
| + return true; |
| + } |
| + } else if ("Deny" == action) { |
| + ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate(); |
| + if (confirm_bar->Cancel()) { |
| + infobar_helper->RemoveInfoBar(infobar); |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| +void NotificationsPermissionTest::GetPrefsByContentSetting( |
| + ContentSetting setting, |
| + ContentSettingsForOneType* settings) { |
| + ASSERT_TRUE(settings != NULL); |
| + DesktopNotificationService* service = GetDesktopNotificationService(); |
| + service->GetNotificationsSettings(settings); |
| + for (ContentSettingsForOneType::iterator it = settings->begin(); |
| + it != settings->end();) { |
| + if (it->setting != setting || it->source.compare(kReference) != 0) { |
| + it = settings->erase(it); |
| + } else { |
| + ++it; |
| + } |
| + } |
| +} |
| + |
| +void NotificationsPermissionTest::PrintSettings( |
| + const ContentSettingsForOneType & settings, |
| + const std::string & type) { |
| + LOG(INFO) << type << ":"; |
| + for (ContentSettingsForOneType::const_iterator it = settings.begin(); |
| + it != settings.end(); ++it) { |
| + LOG(INFO) << it->primary_pattern << "," << it->secondary_pattern << "," |
| + << it->incognito; |
| + } |
| +} |
| + |
| +// If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { |
| ui_test_utils::NavigateToURL( |
| browser(), |
| test_server()->GetURL( |
| @@ -42,8 +669,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { |
| // If this flakes, use http://crbug.com/62311. |
| IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { |
| - ASSERT_TRUE(test_server()->Start()); |
| - |
| // Load a page which just does a request; no user gesture should result |
| // in no infobar. |
| ui_test_utils::NavigateToURL( |
| @@ -54,3 +679,528 @@ IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { |
| EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( |
| chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCreateSimpleNotification) { |
| + // Creates a simple notification. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| + ASSERT_EQ(1U, balloons.size()); |
| + Balloon* balloon = balloons[0]; |
| + const Notification& notification = balloon->notification(); |
| + GURL EXPECTED_ICON_URL = test_server()->GetURL( |
| + "files/notifications/no_such_file.png"); |
|
kkania
2012/11/13 23:38:21
indent 4 from left.
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| + EXPECT_EQ(string16(ASCIIToUTF16("My Title")), notification.title()); |
|
kkania
2012/11/13 23:38:21
string16 constructor is not needed
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + EXPECT_EQ(string16(ASCIIToUTF16("My Body")), notification.body()); |
|
kkania
2012/11/13 23:38:21
here too
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCreateHTMLNotification) { |
| + // Creates an HTML notification using a fake url. |
| + // Note: webkitNotifications.createHTMLNotification is deprecated |
|
kkania
2012/11/13 23:38:21
. at end of comments
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + AllowAllOrigins(); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateHTMLNotification( |
|
kkania
2012/11/13 23:38:21
std::string result = CreateHTMLNotification(
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + "../empty.html", |
| + browser(), |
| + "", |
| + true); |
| + EXPECT_EQ(result, "-1"); |
|
kkania
2012/11/13 23:38:21
the standard is EXPECT_EQ(expected, actual);
You s
kkania
2012/11/13 23:38:21
why is this supposed to be -1? Does the createHTML
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Accoring to http://www.w3.org/TR/notifications/, h
|
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCloseNotification) { |
| + // Creates a notification and closes it. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| + ASSERT_EQ(1U, balloons.size()); |
| + EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
|
kkania
2012/11/13 23:38:21
change this function to GetNotificationCount(), so
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCancelNotification) { |
| + // Creates a notification and cancels it in the origin page. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string note_id = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(note_id, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + CancelNotification(note_id, browser()); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestPermissionInfobarAppears) { |
| + // Requests notification privileges and verifies the infobar appears. |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| + VerifyInfobar(browser(), TEST_PAGE_URL.host(), 0); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestAllowOnPermissionInfobar) { |
| + // Tries to create a notification and clicks allow on the infobar. |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + // This notification should not be shown because we do not have permission. |
| + CreateSimpleNotification(browser(), false); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| + |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + ASSERT_TRUE(PerformActionOnInfobar(browser(), "Allow", 0, 0)); |
| + |
| + CreateSimpleNotification(browser(), true); |
| + EXPECT_TRUE(CheckNotificationCount(1)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestOriginPreferencesBasic) { |
| + // Tests that we can allow and deny origins. |
| + GURL altavista("http://www.altavista.com"); |
| + GURL gmail("http://www.gmail.com"); |
| + GURL yahoo("http://www.yahoo.com"); |
| + |
| + std::vector<GURL> origins; |
| + ContentSettingsForOneType settings; |
| + |
| + origins.push_back(altavista); |
| + origins.push_back(gmail); |
| + |
| + SetDeniedOrigins(origins); |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(2U, settings.size()); |
| + EXPECT_TRUE(checkOriginInSetting(settings, altavista)); |
| + EXPECT_TRUE(checkOriginInSetting(settings, gmail)); |
| + DenyOrigin(yahoo); |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(3U, settings.size()); |
| + EXPECT_TRUE(checkOriginInSetting(settings, yahoo)); |
| + DropOriginPreference(gmail); |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(2U, settings.size()); |
| + EXPECT_FALSE(checkOriginInSetting(settings, gmail)); |
| + |
| + AllowOrigin(yahoo); |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(1U, settings.size()); |
| + EXPECT_FALSE(checkOriginInSetting(settings, yahoo)); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_TRUE(checkOriginInSetting(settings, yahoo)); |
| + |
| + origins.clear(); |
| + origins.push_back(altavista); |
| + origins.push_back(gmail); |
| + SetAllowedOrigins(origins); |
| + origins.clear(); |
| + SetDeniedOrigins(origins); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_TRUE(checkOriginInSetting(settings, altavista)); |
| + EXPECT_TRUE(checkOriginInSetting(settings, gmail)); |
| + AllowOrigin(yahoo); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_TRUE(checkOriginInSetting(settings, yahoo)); |
| + EXPECT_EQ(3U, settings.size()); |
| + DropOriginPreference(gmail); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_EQ(2U, settings.size()); |
| + EXPECT_FALSE(checkOriginInSetting(settings, gmail)); |
| + |
| + DenyOrigin(yahoo); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_EQ(1U, settings.size()); |
| + EXPECT_FALSE(checkOriginInSetting(settings, yahoo)); |
| + GetDeniedOrigins(&settings); |
| + EXPECT_TRUE(checkOriginInSetting(settings, yahoo)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestDenyOnPermissionInfobar) { |
| + // Test that no notification is created |
| + // when Deny is chosen from permission infobar. |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + PerformActionOnInfobar(browser(), "Deny", 0, 0); |
| + CreateSimpleNotification(browser(), false); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| + ContentSettingsForOneType settings; |
| + GetDeniedOrigins(&settings); |
| + EXPECT_TRUE(checkOriginInSetting(settings, TEST_PAGE_URL)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestClosePermissionInfobar) { |
| + // Test that no notification is created when permission infobar is dismissed. |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + PerformActionOnInfobar(browser(), "Dimiss", 0, 0); |
| + CreateSimpleNotification(browser(), false); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| + ContentSettingsForOneType settings; |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(0U, settings.size()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestNotificationWithPropertyMissing) { |
| + // Test that a notification can be created if one property is missing. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| + ASSERT_EQ(1U, balloons.size()); |
| + Balloon* balloon = balloons[0]; |
| + const Notification& notification = balloon->notification(); |
| + GURL EXPECTED_ICON_URL = test_server()->GetURL( |
|
kkania
2012/11/13 23:38:21
kExpectedIconUrl
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| + "files/notifications/no_such_file.png"); |
| + EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| + EXPECT_EQ(string16(ASCIIToUTF16("My Title")), notification.title()); |
|
kkania
2012/11/13 23:38:21
string16 constructor is not needed
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Done.
|
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestAllowNotificationsFromAllSites) { |
| + // Verify that all domains can be allowed to show notifications. |
| + SetDefaultPermissionSetting(kAllowAllSetting); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestDenyNotificationsFromAllSites) { |
| + // Verify that no domain can show notifications. |
| + SetDefaultPermissionSetting(kDenyAllSetting); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), false); |
| + EXPECT_EQ(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestDenyDomainAndAllowAll) { |
| + // Verify that denying a domain and allowing all shouldn't show |
| + // notifications from the denied domain. |
| + DenyOrigin(TEST_PAGE_URL.GetOrigin()); |
| + SetDefaultPermissionSetting(kAllowAllSetting); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), false); |
| + EXPECT_EQ(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestAllowDomainAndDenyAll) { |
| + // Verify that allowing a domain and denying all others should show |
| + // notifications from the allowed domain. |
| + AllowOrigin(TEST_PAGE_URL.GetOrigin()); |
| + SetDefaultPermissionSetting(kDenyAllSetting); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestDenyAndThenAllowDomain) { |
| + // Verify that denying and again allowing should show notifications. |
| + DenyOrigin(TEST_PAGE_URL.GetOrigin()); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateSimpleNotification(browser(), false); |
| + EXPECT_EQ(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| + |
| + AllowOrigin(TEST_PAGE_URL.GetOrigin()); |
| + result = CreateSimpleNotification(browser(), true); |
| + EXPECT_NE(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( |
| + chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCreateDenyCloseNotifications) { |
| + // Verify able to create, deny, and close the notification. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + CreateSimpleNotification(browser(), true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + |
| + DenyOrigin(TEST_PAGE_URL.GetOrigin()); |
| + ContentSettingsForOneType settings; |
| + GetDeniedOrigins(&settings); |
| + ASSERT_TRUE(checkOriginInSetting(settings, TEST_PAGE_URL.GetOrigin())); |
| + |
| + const std::deque<Balloon*>& balloons1 = GetActiveBalloons(); |
| + EXPECT_EQ(1U, balloons1.size()); |
| + ASSERT_TRUE(CloseNotificationAndWait(balloons1[0]->notification())); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +// Crashes on Linux/Win. See http://crbug.com/160657. |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + DISABLED_TestOriginPrefsNotSavedInIncognito) { |
| + // Verify that allow/deny origin preferences are not saved in incognito. |
| + Browser* incognito = CreateBrowserWindow(browser(), true); |
| + ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL); |
| + RequestPermission(incognito); |
| + ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true)); |
| + PerformActionOnInfobar(incognito, "Deny", 0, 0); |
| + CloseBrowserWindow(incognito); |
| + |
| + incognito = CreateBrowserWindow(browser(), true); |
| + ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL); |
| + RequestPermission(incognito); |
| + ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true)); |
| + PerformActionOnInfobar(incognito, "Allow", 0, 0); |
| + CreateSimpleNotification(incognito, true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + CloseBrowserWindow(incognito); |
| + |
| + incognito = CreateBrowserWindow(browser(), true); |
| + ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL); |
| + RequestPermission(incognito); |
| + ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true)); |
| + |
| + ContentSettingsForOneType settings; |
| + GetDeniedOrigins(&settings); |
| + EXPECT_EQ(0U, settings.size()); |
| + GetAllowedOrigins(&settings); |
| + EXPECT_EQ(0U, settings.size()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestExitBrowserWithInfobar) { |
| + // Exit the browser window, when the infobar appears. |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCrashTabWithPermissionInfobar) { |
| + // Test crashing the tab with permission infobar doesn't crash Chrome. |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), |
| + EMPTY_PAGE_URL, |
| + NEW_BACKGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| + chrome::ActivateTabAt(browser(), 0, true); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + CrashTab(browser(), 0); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestKillNotificationProcess) { |
| + // Test killing a notification doesn't crash Chrome. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + CreateSimpleNotification(browser(), true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + |
| + const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| + ASSERT_EQ(1U, balloons.size()); |
| + CrashNotification(balloons[0]); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestIncognitoNotification) { |
| + // Test notifications in incognito window. |
| + Browser* browser = CreateIncognitoBrowser(); |
| + ui_test_utils::NavigateToURL(browser, TEST_PAGE_URL); |
| + chrome::ActivateTabAt(browser, 0, true); |
| + RequestPermission(browser); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser, 1, 0, true)); |
| + PerformActionOnInfobar(browser, "Allow", 0, 0); |
| + CreateSimpleNotification(browser, true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestSpecialURLNotification) { |
| + // Test a page cannot create a notification to a chrome: url. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + CreateHTMLNotification("chrome://settings", browser(), "", true); |
| + ASSERT_TRUE(CheckNotificationCount(0)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCloseTabWithPermissionInfobar) { |
| + // Test that user can close tab when infobar present. |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), |
| + GURL("about:blank"), |
| + NEW_BACKGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| + chrome::ActivateTabAt(browser(), 0, true); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + CloseTab(browser(), 0); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestNavigateAwayWithPermissionInfobar) { |
| + // Test navigating away when an infobar is present, |
| + // then trying to create a notification from the same page. |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), |
| + GURL("about:blank"), |
| + NEW_BACKGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| + chrome::ActivateTabAt(browser(), 0, true); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + RequestPermission(browser()); |
| + ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true)); |
| + PerformActionOnInfobar(browser(), "Allow", 0, 0); |
| + CreateSimpleNotification(browser(), true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestCrashRendererNotificationRemain) { |
| + // Test crashing renderer does not close or crash notification. |
| + AllowAllOrigins(); |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), |
| + GURL("about:blank"), |
| + NEW_BACKGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| + chrome::ActivateTabAt(browser(), 0, true); |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + CreateSimpleNotification(browser(), true); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + CrashTab(browser(), 0); |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestNotificationOrderAfterClosingOne) { |
| + // Tests that closing a notification leaves the rest |
| + // of the notifications in the correct order. |
| + // check for Win7 |
| +#if defined(OS_WIN) |
| + if (base::win::GetVersion() == VERSION_WIN7) { |
| + return; // crbug.com/66072 |
|
kkania
2012/11/13 23:38:21
this bug says the test is currently disabled on ma
chrisgao (Use stgao instead)
2012/11/14 21:38:28
Not sure about that.
Should we disable this testca
|
| + } |
| +#endif |
| + |
| + AllowAllOrigins(); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + CreateNotification(browser(), true, "", "Title1", "", "1"); |
| + CreateNotification(browser(), true, "", "Title2", "", "2"); |
| + CreateNotification(browser(), true, "", "Title3", "", "3"); |
| + |
| + EXPECT_TRUE(CheckNotificationCount(3)); |
| + const std::deque<Balloon*>& old_balloons = GetActiveBalloons(); |
| + |
| + ASSERT_TRUE(CloseNotificationAndWait(old_balloons[1]->notification())); |
| + |
| + const std::deque<Balloon*>& new_balloons = GetActiveBalloons(); |
| + ASSERT_EQ(2U, new_balloons.size()); |
| + EXPECT_EQ(old_balloons[0]->notification().notification_id(), |
| + new_balloons[0]->notification().notification_id()); |
| + EXPECT_EQ(old_balloons[2]->notification().notification_id(), |
| + new_balloons[1]->notification().notification_id()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F( |
| + NotificationsPermissionTest, |
| + TestNotificationReplacement) { |
| + // Test that we can replace a notification using the replaceId. |
| + AllowAllOrigins(); |
| + |
| + ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL); |
| + |
| + std::string result = CreateNotification( |
| + browser(), |
| + true, |
| + "", |
| + "Title2", |
| + "", |
| + "chat"); |
| + EXPECT_NE(result, "-1"); |
| + |
| + ASSERT_TRUE(CheckNotificationCount(1)); |
| + |
| + result = CreateNotification( |
| + browser(), |
| + false, |
| + "no_such_file.png", |
| + "", |
| + "", |
| + "chat"); |
| + EXPECT_NE(result, "-1"); |
| + |
| + const std::deque<Balloon*>& balloons2 = GetActiveBalloons(); |
| + EXPECT_EQ(1U, balloons2.size()); |
| + GURL EXPECTED_ICON_URL = test_server()->GetURL( |
| + "files/notifications/no_such_file.png"); |
| + const Notification& notification = balloons2[0]->notification(); |
| + EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| +} |