Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Unified Diff: chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc

Issue 13139004: Deprecate Browser::TYPE_PANEL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc b/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
index 9ca03c1f438f3d238c54e9e70faf76f5960a8f1a..54863bcf665241b1d69750650d104e077f60ec91 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
@@ -2,49 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <vector>
+#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
-#include "ash/ash_switches.h"
-#include "base/command_line.h"
-#include "base/files/file_path.h"
+#include "ash/launcher/launcher_types.h"
+#include "base/memory/scoped_ptr.h"
#include "base/stringprintf.h"
-#include "base/time.h"
-#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
-#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
-#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
-#include "content/public/common/favicon_url.h"
-#include "net/test/test_server.h"
-#include "testing/gtest/include/gtest/gtest.h"
-// TODO(skuhne): Remove this module together with launcher_favicon_loader.*
-// when the old launcher goes away.
+using content::WebContents;
+using content::WebContentsObserver;
namespace {
// Observer class to determine when favicons have completed loading.
-class ContentsObserver : public content::WebContentsObserver {
+class ContentsObserver : public WebContentsObserver {
public:
- explicit ContentsObserver(content::WebContents* web_contents)
- : content::WebContentsObserver(web_contents),
+ explicit ContentsObserver(WebContents* web_contents)
+ : WebContentsObserver(web_contents),
+ loaded_(false),
got_favicons_(false) {
}
virtual ~ContentsObserver() {}
- bool got_favicons() const { return got_favicons_; }
void Reset() {
got_favicons_ = false;
}
- // content::WebContentsObserver overrides.
+ bool loaded() const { return loaded_; }
+ bool got_favicons() const { return got_favicons_; }
+
+ // WebContentsObserver overrides.
+ virtual void DidFinishLoad(
+ int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame,
+ content::RenderViewHost* render_view_host) OVERRIDE {
+ loaded_ = true;
+ }
+
virtual void DidUpdateFaviconURL(int32 page_id,
const std::vector<content::FaviconURL>& candidates) OVERRIDE {
if (!candidates.empty())
@@ -52,149 +53,136 @@ class ContentsObserver : public content::WebContentsObserver {
}
private:
+ bool loaded_;
bool got_favicons_;
};
} // namespace
-class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest {
+class LauncherFaviconLoaderBrowsertest
+ : public InProcessBrowserTest,
+ public LauncherFaviconLoader::Delegate {
public:
- LauncherFaviconLoaderBrowsertest()
- : panel_browser_(NULL),
- loader_(NULL),
- contents_observer_(NULL) {
+ LauncherFaviconLoaderBrowsertest() : favicon_updated_(false) {
}
virtual ~LauncherFaviconLoaderBrowsertest() {
}
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
- InProcessBrowserTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher);
+ virtual void SetUpOnMainThread() {
+ WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ contents_observer_.reset(new ContentsObserver(web_contents));
+ favicon_loader_.reset(new LauncherFaviconLoader(this, web_contents));
}
- protected:
- void NavigateTo(const char* url) {
- Browser* browser = GetPanelBrowser();
- std::string url_path = base::StringPrintf("files/ash/launcher/%s", url);
- ui_test_utils::NavigateToURL(browser, test_server()->GetURL(url_path));
+ // LauncherFaviconLoader::Delegate overrides:
+ virtual void FaviconUpdated() OVERRIDE {
+ favicon_updated_ = true;
}
- Browser* GetPanelBrowser() {
- if (!panel_browser_) {
- panel_browser_ = new Browser(Browser::CreateParams::CreateForApp(
- Browser::TYPE_PANEL, "Test Panel", gfx::Rect(),
- browser()->profile(), browser()->host_desktop_type()));
- EXPECT_TRUE(panel_browser_->is_type_panel());
- // Load initial web contents before setting the observer.
- ui_test_utils::NavigateToURL(panel_browser_, GURL());
- EXPECT_FALSE(contents_observer_.get());
- contents_observer_.reset(
- new ContentsObserver(
- panel_browser_->tab_strip_model()->GetWebContentsAt(0)));
- }
- return panel_browser_;
+ protected:
+ bool NavigateTo(const char* url) {
+ std::string url_path = base::StringPrintf("files/ash/launcher/%s", url);
+ ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(url_path));
+ return true;
}
- LauncherFaviconLoader* GetFaviconLoader() {
- if (!loader_) {
- Browser* browser = GetPanelBrowser();
- BrowserView* browser_view = static_cast<BrowserView*>(browser->window());
- BrowserLauncherItemController* launcher_item_controller =
- browser_view->launcher_item_controller();
- if (!launcher_item_controller)
- return NULL;
- EXPECT_EQ(BrowserLauncherItemController::TYPE_EXTENSION_PANEL,
- launcher_item_controller->type());
- loader_ = launcher_item_controller->favicon_loader();
+ bool WaitForContentsLoaded() {
+ const int64 max_seconds = 10;
+ base::Time start_time = base::Time::Now();
+ while (!(contents_observer_->loaded() &&
+ contents_observer_->got_favicons())) {
+ content::RunAllPendingInMessageLoop();
+ base::TimeDelta delta = base::Time::Now() - start_time;
+ if (delta.InSeconds() >= max_seconds) {
+ LOG(ERROR) << " WaitForContentsLoaded timed out.";
+ return false;
+ }
}
- return loader_;
- }
-
- void ResetDownloads() {
- ASSERT_NE(static_cast<void*>(NULL), contents_observer_.get());
- contents_observer_->Reset();
+ return true;
}
- bool WaitForFaviconDownloads() {
- LauncherFaviconLoader* loader = GetFaviconLoader();
- if (!loader)
- return false;
-
- const int64 max_seconds = 2;
+ bool WaitForFaviconUpdated() {
+ const int64 max_seconds = 10;
base::Time start_time = base::Time::Now();
- while (!contents_observer_->got_favicons() ||
- loader->HasPendingDownloads()) {
+ while (favicon_loader_->HasPendingDownloads()) {
content::RunAllPendingInMessageLoop();
base::TimeDelta delta = base::Time::Now() - start_time;
if (delta.InSeconds() >= max_seconds) {
- LOG(ERROR) << " WaitForFaviconDownlads timed out:"
- << " Got Favicons:" << contents_observer_->got_favicons()
- << " Pending Downloads: " << loader->HasPendingDownloads();
+ LOG(ERROR) << " WaitForFaviconDownlads timed out.";
return false;
}
}
return true;
}
- private:
- Browser* panel_browser_;
- LauncherFaviconLoader* loader_;
+ void ResetDownloads() {
+ contents_observer_->Reset();
+ }
+
+ bool favicon_updated_;
scoped_ptr<ContentsObserver> contents_observer_;
+ scoped_ptr<LauncherFaviconLoader> favicon_loader_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoaderBrowsertest);
};
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) {
ASSERT_TRUE(test_server()->Start());
- NavigateTo("launcher-smallfavicon.html");
- LauncherFaviconLoader* favicon_loader = GetFaviconLoader();
- ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
- EXPECT_TRUE(WaitForFaviconDownloads());
+ ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html"));
+ EXPECT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
+
// No large favicons specified, bitmap should be empty.
- EXPECT_TRUE(favicon_loader->GetFavicon().empty());
+ EXPECT_TRUE(favicon_loader_->GetFavicon().empty());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) {
ASSERT_TRUE(test_server()->Start());
- NavigateTo("launcher-largefavicon.html");
- LauncherFaviconLoader* favicon_loader = GetFaviconLoader();
- ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
- EXPECT_TRUE(WaitForFaviconDownloads());
- EXPECT_FALSE(favicon_loader->GetFavicon().empty());
- EXPECT_EQ(128, favicon_loader->GetFavicon().height());
+ ASSERT_TRUE(NavigateTo("launcher-largefavicon.html"));
+ EXPECT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
+
+ EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
+ EXPECT_EQ(128, favicon_loader_->GetFavicon().height());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) {
ASSERT_TRUE(test_server()->Start());
- NavigateTo("launcher-manyfavicon.html");
- LauncherFaviconLoader* favicon_loader = GetFaviconLoader();
- ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
+ ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html"));
+ EXPECT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
- EXPECT_TRUE(WaitForFaviconDownloads());
- EXPECT_FALSE(favicon_loader->GetFavicon().empty());
+ EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
// When multiple favicons are present, the correctly sized icon should be
// chosen. The icons are sized assuming ash::kLauncherPreferredSize < 128.
EXPECT_GT(128, ash::kLauncherPreferredSize);
- EXPECT_EQ(48, favicon_loader->GetFavicon().height());
+ EXPECT_EQ(48, favicon_loader_->GetFavicon().height());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) {
ASSERT_TRUE(test_server()->Start());
- NavigateTo("launcher-manyfavicon.html");
- LauncherFaviconLoader* favicon_loader = GetFaviconLoader();
- ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
+ ASSERT_TRUE(NavigateTo("launcher-manyfavicon.html"));
+ EXPECT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
- EXPECT_TRUE(WaitForFaviconDownloads());
- EXPECT_FALSE(favicon_loader->GetFavicon().empty());
- EXPECT_EQ(48, favicon_loader->GetFavicon().height());
+ EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
+ EXPECT_EQ(48, favicon_loader_->GetFavicon().height());
ASSERT_NO_FATAL_FAILURE(ResetDownloads());
- NavigateTo("launcher-smallfavicon.html");
- EXPECT_TRUE(WaitForFaviconDownloads());
- EXPECT_TRUE(favicon_loader->GetFavicon().empty());
+ ASSERT_TRUE(NavigateTo("launcher-smallfavicon.html"));
+ ASSERT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
+
+ EXPECT_TRUE(favicon_loader_->GetFavicon().empty());
ASSERT_NO_FATAL_FAILURE(ResetDownloads());
- NavigateTo("launcher-largefavicon.html");
- EXPECT_TRUE(WaitForFaviconDownloads());
- EXPECT_FALSE(favicon_loader->GetFavicon().empty());
- EXPECT_EQ(128, favicon_loader->GetFavicon().height());
+ ASSERT_TRUE(NavigateTo("launcher-largefavicon.html"));
+ ASSERT_TRUE(WaitForContentsLoaded());
+ EXPECT_TRUE(WaitForFaviconUpdated());
+
+ EXPECT_FALSE(favicon_loader_->GetFavicon().empty());
+ EXPECT_EQ(128, favicon_loader_->GetFavicon().height());
}

Powered by Google App Engine
This is Rietveld 408576698