Commit cf1c7cec authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: adds test for favicons when off-the-record

components/favicon was made to deal with a null CoreFaviconService,
so no changes are necessary in the weblayer side. This adds a
test to ensure it works.

BUG=1076463
TEST=none

Change-Id: I52eafced0f77a3d3a764097dcdca4e0b33b6442e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339288
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796611}
parent e7f0733c
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
#include "weblayer/browser/favicon/favicon_fetcher_impl.h" #include "weblayer/browser/favicon/favicon_fetcher_impl.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "build/build_config.h"
#include "components/favicon/content/content_favicon_driver.h" #include "components/favicon/content/content_favicon_driver.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "weblayer/browser/browser_context_impl.h"
#include "weblayer/browser/favicon/favicon_fetcher_impl.h" #include "weblayer/browser/favicon/favicon_fetcher_impl.h"
#include "weblayer/browser/favicon/favicon_service_impl.h" #include "weblayer/browser/favicon/favicon_service_impl.h"
#include "weblayer/browser/favicon/favicon_service_impl_factory.h" #include "weblayer/browser/favicon/favicon_service_impl_factory.h"
#include "weblayer/browser/favicon/favicon_service_impl_observer.h" #include "weblayer/browser/favicon/favicon_service_impl_observer.h"
#include "weblayer/browser/favicon/test_favicon_fetcher_delegate.h" #include "weblayer/browser/favicon/test_favicon_fetcher_delegate.h"
#include "weblayer/browser/profile_impl.h"
#include "weblayer/browser/tab_impl.h" #include "weblayer/browser/tab_impl.h"
#include "weblayer/public/browser.h"
#include "weblayer/public/favicon_fetcher_delegate.h" #include "weblayer/public/favicon_fetcher_delegate.h"
#include "weblayer/public/navigation_controller.h" #include "weblayer/public/navigation_controller.h"
#include "weblayer/shell/browser/shell.h" #include "weblayer/shell/browser/shell.h"
...@@ -133,4 +137,30 @@ IN_PROC_BROWSER_TEST_F(FaviconFetcherBrowserTest, ...@@ -133,4 +137,30 @@ IN_PROC_BROWSER_TEST_F(FaviconFetcherBrowserTest,
EXPECT_FALSE(fetcher_delegate.last_image().IsEmpty()); EXPECT_FALSE(fetcher_delegate.last_image().IsEmpty());
} }
// This test creates a Browser and Tab, which doesn't work well with Java when
// driven from native code.
#if !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(FaviconFetcherBrowserTest, OffTheRecord) {
auto otr_profile = Profile::Create(std::string());
ProfileImpl* otr_profile_impl = static_cast<ProfileImpl*>(otr_profile.get());
EXPECT_TRUE(otr_profile_impl->GetBrowserContext()->IsOffTheRecord());
auto otr_browser = Browser::Create(otr_profile.get(), nullptr);
Tab* tab = otr_browser->CreateTab();
// There is no FaviconService for off the record profiles. FaviconService
// writes to disk, which is not appropriate for off the record mode.
EXPECT_EQ(nullptr,
FaviconServiceImplFactory::GetForProfile(otr_profile_impl));
ASSERT_TRUE(embedded_test_server()->Start());
TestFaviconFetcherDelegate fetcher_delegate;
auto fetcher = tab->CreateFaviconFetcher(&fetcher_delegate);
NavigateAndWaitForCompletion(
embedded_test_server()->GetURL("/simple_page_with_favicon.html"), tab);
fetcher_delegate.WaitForFavicon();
EXPECT_FALSE(fetcher_delegate.last_image().IsEmpty());
EXPECT_EQ(fetcher_delegate.last_image(), fetcher->GetFavicon());
EXPECT_EQ(1, fetcher_delegate.on_favicon_changed_call_count());
}
#endif
} // namespace weblayer } // namespace weblayer
...@@ -37,7 +37,6 @@ FaviconServiceImplFactory::~FaviconServiceImplFactory() = default; ...@@ -37,7 +37,6 @@ FaviconServiceImplFactory::~FaviconServiceImplFactory() = default;
KeyedService* FaviconServiceImplFactory::BuildServiceInstanceFor( KeyedService* FaviconServiceImplFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
// TODO(sky): figure out best way to support incognito.
DCHECK(!context->IsOffTheRecord()); DCHECK(!context->IsOffTheRecord());
std::unique_ptr<FaviconServiceImpl> service = std::unique_ptr<FaviconServiceImpl> service =
std::make_unique<FaviconServiceImpl>(); std::make_unique<FaviconServiceImpl>();
......
...@@ -20,6 +20,7 @@ class FaviconServiceImplFactory : public BrowserContextKeyedServiceFactory { ...@@ -20,6 +20,7 @@ class FaviconServiceImplFactory : public BrowserContextKeyedServiceFactory {
FaviconServiceImplFactory& operator=(const FaviconServiceImplFactory&) = FaviconServiceImplFactory& operator=(const FaviconServiceImplFactory&) =
delete; delete;
// Off the record profiles do not have a FaviconServiceImpl.
static FaviconServiceImpl* GetForProfile(ProfileImpl* profile); static FaviconServiceImpl* GetForProfile(ProfileImpl* profile);
// Returns the FaviconServiceFactory singleton. // Returns the FaviconServiceFactory singleton.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment