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

Side by Side Diff: ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl_unittest.mm

Issue 2529283002: Save favicon during reading list distillation (Closed)
Patch Set: Fix test Created 3 years, 12 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "components/favicon/ios/web_favicon_driver.h"
9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
10 #import "ios/testing/wait_util.h"
11 #include "ios/web/public/test/test_web_thread_bundle.h"
12 #include "ios/web/public/web_state/web_state_observer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h"
15
16 namespace dom_distiller {
17
18 // Test class.
19 class FaviconWebStateDispatcherTest : public PlatformTest {
20 public:
21 FaviconWebStateDispatcherTest() : web_state_destroyed_(false) {
22 TestChromeBrowserState::Builder builder;
23 browser_state_ = builder.Build();
24 }
25
26 web::BrowserState* GetBrowserState() { return browser_state_.get(); }
27
28 bool IsWebStateDestroyed() { return web_state_destroyed_; }
29 void WebStateDestroyed() { web_state_destroyed_ = true; }
30
31 private:
32 web::TestWebThreadBundle thread_bundle_;
33 std::unique_ptr<TestChromeBrowserState> browser_state_;
34 bool web_state_destroyed_;
35 };
36
37 // Observer for the test.
38 class TestFaviconWebStateDispatcherObserver : public web::WebStateObserver {
39 public:
40 TestFaviconWebStateDispatcherObserver(web::WebState* web_state,
41 FaviconWebStateDispatcherTest* owner)
42 : web::WebStateObserver(web_state), owner_(owner) {}
43
44 // WebStateObserver implementation:
45 void WebStateDestroyed() override { owner_->WebStateDestroyed(); };
46
47 private:
48 FaviconWebStateDispatcherTest* owner_; // weak, owns this object.
49 };
50
51 // Tests that RequestWebState returns a WebState with a FaviconDriver attached.
52 TEST_F(FaviconWebStateDispatcherTest, RequestWebState) {
53 FaviconWebStateDispatcherImpl dispatcher(GetBrowserState(), -1);
54 web::WebState* web_state = dispatcher.RequestWebState();
55
56 favicon::WebFaviconDriver* driver =
57 favicon::WebFaviconDriver::FromWebState(web_state);
58 EXPECT_NE(driver, nullptr);
59 }
60
61 // Tests that the WebState returned will be destroyed after a delay.
62 TEST_F(FaviconWebStateDispatcherTest, ReturnWebState) {
63 FaviconWebStateDispatcherImpl dispatcher(GetBrowserState(), 0);
64 web::WebState* web_state = dispatcher.RequestWebState();
65
66 TestFaviconWebStateDispatcherObserver observer(web_state, this);
67
68 ConditionBlock condition = ^{
69 return IsWebStateDestroyed();
70 };
71
72 dispatcher.ReturnWebState(web_state);
73
74 ASSERT_TRUE(testing::WaitUntilConditionOrTimeout(0.5, condition));
75 }
76 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl.mm ('k') | ios/chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698