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

Unified Diff: ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm

Issue 2529283002: Save favicon during reading list distillation (Closed)
Patch Set: Change map to vector Created 4 years 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: ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm
diff --git a/ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm b/ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ea1a97dd52f58571e1980cb589026bdd5b91f385
--- /dev/null
+++ b/ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm
@@ -0,0 +1,76 @@
+// Copyright 2016 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.
+
+#import "ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl.h"
+
+#include "base/memory/ptr_util.h"
+#include "components/favicon/ios/web_favicon_driver.h"
+#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
+#import "ios/testing/wait_util.h"
+#include "ios/web/public/test/test_web_thread_bundle.h"
+#include "ios/web/public/web_state/web_state_observer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace dom_distiller {
+
+// Test class.
+class FaviconWebStateDispatcherTest : public PlatformTest {
+ public:
+ FaviconWebStateDispatcherTest() : web_state_destroyed_(false) {
+ TestChromeBrowserState::Builder builder;
+ browser_state_ = builder.Build();
+ }
+
+ web::BrowserState* GetBrowserState() { return browser_state_.get(); }
+
+ bool IsWebStateDestroyed() { return web_state_destroyed_; }
+ void WebStateDestroyed() { web_state_destroyed_ = true; }
+
+ private:
+ web::TestWebThreadBundle thread_bundle_;
+ std::unique_ptr<TestChromeBrowserState> browser_state_;
+ bool web_state_destroyed_;
+};
+
+// Observer for the test.
+class TestFaviconWebStateDispatcherObserver : public web::WebStateObserver {
+ public:
+ TestFaviconWebStateDispatcherObserver(web::WebState* web_state,
+ FaviconWebStateDispatcherTest* owner)
+ : web::WebStateObserver(web_state), owner_(owner) {}
+
+ // WebStateObserver implementation:
+ void WebStateDestroyed() override { owner_->WebStateDestroyed(); };
+
+ private:
+ FaviconWebStateDispatcherTest* owner_; // weak, owns this object.
+};
+
+// Tests that RequestWebState returns a WebState with a FaviconDriver attached.
+TEST_F(FaviconWebStateDispatcherTest, RequestWebState) {
+ FaviconWebStateDispatcherImpl dispatcher(GetBrowserState());
+ web::WebState* web_state = dispatcher.RequestWebState();
+
+ favicon::WebFaviconDriver* driver =
+ favicon::WebFaviconDriver::FromWebState(web_state);
+ EXPECT_NE(driver, nullptr);
+}
+
+// Tests that the WebState returned will be destroyed after a delay.
+TEST_F(FaviconWebStateDispatcherTest, ReturnWebState) {
+ FaviconWebStateDispatcherImpl dispatcher(GetBrowserState(), 0);
+ web::WebState* web_state = dispatcher.RequestWebState();
+
+ TestFaviconWebStateDispatcherObserver observer(web_state, this);
+
+ ConditionBlock condition = ^{
+ return IsWebStateDestroyed();
+ };
+
+ dispatcher.ReturnWebState(web_state);
+
+ ASSERT_TRUE(testing::WaitUntilConditionOrTimeout(0.5, condition));
+}
+} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698