summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 13:10:03 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 13:10:03 +0000
commitd818e07fb7b4e680de9a38ad7af55ba04acb2cbf (patch)
tree6be52cdcff66f0c5972ce80feef7dbcf392ad899 /chrome/browser/extensions
parentd267ee95429eca5bff2e2d499725ca222848a1cf (diff)
downloadchromium_src-d818e07fb7b4e680de9a38ad7af55ba04acb2cbf.zip
chromium_src-d818e07fb7b4e680de9a38ad7af55ba04acb2cbf.tar.gz
chromium_src-d818e07fb7b4e680de9a38ad7af55ba04acb2cbf.tar.bz2
Remove poll'n'loop code from extension_browsertest.cc.
Also use a common wait function from extension_browsertest in the page action popup test. BUG=34339 TEST=browser_tests Review URL: http://codereview.chromium.org/582013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc93
-rw-r--r--chrome/browser/extensions/extension_browsertest.h10
-rw-r--r--chrome/browser/extensions/page_action_apitest.cc64
3 files changed, 71 insertions, 96 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index 4e25a8a..7bb8084 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -30,6 +30,11 @@
// minimize false positives.
static const int kTimeoutMs = 60 * 1000; // 1 minute
+ExtensionBrowserTest::ExtensionBrowserTest()
+ : target_page_action_count_(-1),
+ target_visible_page_action_count_(-1) {
+}
+
void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) {
// This enables DOM automation for tab contentses.
EnableDOMAutomation();
@@ -161,49 +166,37 @@ void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) {
}
bool ExtensionBrowserTest::WaitForPageActionCountChangeTo(int count) {
- base::Time start_time = base::Time::Now();
- while (true) {
- LocationBarTesting* loc_bar =
- browser()->window()->GetLocationBar()->GetLocationBarForTesting();
-
- int actions = loc_bar->PageActionCount();
- if (actions == count)
- return true;
-
- if ((base::Time::Now() - start_time).InMilliseconds() > kTimeoutMs) {
- std::cout << "Timed out waiting for page actions to (un)load.\n"
- << "Currently loaded page actions: " << IntToString(actions)
- << "\n";
- return false;
- }
+ NotificationRegistrar registrar;
+ registrar.Add(this,
+ NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED,
+ NotificationService::AllSources());
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- new MessageLoop::QuitTask, 200);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask,
+ kTimeoutMs);
+
+ target_page_action_count_ = count;
+ LocationBarTesting* location_bar =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
+ if (location_bar->PageActionCount() != count)
ui_test_utils::RunMessageLoop();
- }
+ return location_bar->PageActionCount() == count;
}
bool ExtensionBrowserTest::WaitForPageActionVisibilityChangeTo(int count) {
- base::Time start_time = base::Time::Now();
- while (true) {
- LocationBarTesting* loc_bar =
- browser()->window()->GetLocationBar()->GetLocationBarForTesting();
-
- int visible = loc_bar->PageActionVisibleCount();
- if (visible == count)
- return true;
-
- if ((base::Time::Now() - start_time).InMilliseconds() > kTimeoutMs) {
- std::cout << "Timed out waiting for page actions to become (in)visible.\n"
- << "Currently visible page actions: " << IntToString(visible)
- << "\n";
- return false;
- }
+ NotificationRegistrar registrar;
+ registrar.Add(this,
+ NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
+ NotificationService::AllSources());
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- new MessageLoop::QuitTask, 200);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask,
+ kTimeoutMs);
+
+ target_visible_page_action_count_ = count;
+ LocationBarTesting* location_bar =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
+ if (location_bar->PageActionVisibleCount() != count)
ui_test_utils::RunMessageLoop();
- }
+ return location_bar->PageActionVisibleCount() == count;
}
bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() {
@@ -315,6 +308,34 @@ void ExtensionBrowserTest::Observe(NotificationType type,
MessageLoopForUI::current()->Quit();
break;
+ case NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED: {
+ LocationBarTesting* location_bar =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
+ std::cout << "Got EXTENSION_PAGE_ACTION_COUNT_CHANGED "
+ << "notification. Number of page actions: "
+ << location_bar->PageActionCount() << "\n";
+ if (location_bar->PageActionCount() ==
+ target_page_action_count_) {
+ target_page_action_count_ = -1;
+ MessageLoopForUI::current()->Quit();
+ }
+ break;
+ }
+
+ case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: {
+ LocationBarTesting* location_bar =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
+ std::cout << "Got EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED "
+ << "notification. Number of visible page actions: "
+ << location_bar->PageActionVisibleCount() << "\n";
+ if (location_bar->PageActionVisibleCount() ==
+ target_visible_page_action_count_) {
+ target_visible_page_action_count_ = -1;
+ MessageLoopForUI::current()->Quit();
+ }
+ break;
+ }
+
default:
NOTREACHED();
break;
diff --git a/chrome/browser/extensions/extension_browsertest.h b/chrome/browser/extensions/extension_browsertest.h
index c0534d1..a284607 100644
--- a/chrome/browser/extensions/extension_browsertest.h
+++ b/chrome/browser/extensions/extension_browsertest.h
@@ -20,6 +20,8 @@
class ExtensionBrowserTest
: public InProcessBrowserTest, public NotificationObserver {
protected:
+ ExtensionBrowserTest();
+
virtual void SetUpCommandLine(CommandLine* command_line);
bool LoadExtension(const FilePath& path);
@@ -89,6 +91,14 @@ class ExtensionBrowserTest
int expected_change);
bool WaitForExtensionHostsToLoad();
+
+ // When waiting for page action count to change, we wait until it reaches this
+ // value.
+ int target_page_action_count_;
+
+ // When waiting for visible page action count to change, we wait until it
+ // reaches this value.
+ int target_visible_page_action_count_;
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSERTEST_H_
diff --git a/chrome/browser/extensions/page_action_apitest.cc b/chrome/browser/extensions/page_action_apitest.cc
index 5b42890..c165623 100644
--- a/chrome/browser/extensions/page_action_apitest.cc
+++ b/chrome/browser/extensions/page_action_apitest.cc
@@ -157,74 +157,18 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) {
}
}
-class PageActionPopupTest : public ExtensionApiTest {
-public:
- bool RunExtensionTest(const char* extension_name) {
- last_action_ = NULL;
- last_visibility_ = false;
- waiting_ = false;
-
- return ExtensionApiTest::RunExtensionTest(extension_name);
- };
-
- void Observe(NotificationType type, const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type.value) {
- case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: {
- last_action_ = Source<ExtensionAction>(source).ptr();
- TabContents* contents = Details<TabContents>(details).ptr();
- int tab_id = ExtensionTabUtil::GetTabId(contents);
- last_visibility_ = last_action_->GetIsVisible(tab_id);
- if (waiting_)
- MessageLoopForUI::current()->Quit();
- break;
- }
- default:
- ExtensionBrowserTest::Observe(type, source, details);
- break;
- }
- }
-
- void WaitForPopupVisibilityChange() {
- // Wait for EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED to come in.
- if (!last_action_) {
- waiting_ = true;
- ui_test_utils::RunMessageLoop();
- waiting_ = false;
- }
- }
-
- protected:
- bool waiting_;
- ExtensionAction* last_action_;
- bool last_visibility_;
-};
-
// Tests popups in page actions.
-IN_PROC_BROWSER_TEST_F(PageActionPopupTest, Show) {
- NotificationRegistrar registrar;
- registrar.Add(this,
- NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
- NotificationService::AllSources());
-
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ShowPageActionPopup) {
ASSERT_TRUE(RunExtensionTest("page_action/popup")) << message_;
Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
- // Wait for The page action to actually become visible.
- if (!last_visibility_)
- last_action_ = NULL;
- WaitForPopupVisibilityChange();
- ASSERT_TRUE(last_visibility_);
-
- LocationBarTesting* location_bar =
- browser()->window()->GetLocationBar()->GetLocationBarForTesting();
- ASSERT_EQ(1, location_bar->PageActionVisibleCount());
- ExtensionAction* action = location_bar->GetVisiblePageAction(0);
- EXPECT_EQ(action, last_action_);
+ ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
{
ResultCatcher catcher;
+ LocationBarTesting* location_bar =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
location_bar->TestPageActionPressed(0);
ASSERT_TRUE(catcher.GetNextResult());
}