OLD | NEW |
---|---|
(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 #include "base/memory/ptr_util.h" | |
6 #include "components/favicon/ios/web_favicon_driver.h" | |
7 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | |
8 #include "ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl.h" | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
This include should go first, then a line-break th
gambard
2016/12/20 08:54:22
Done.
| |
9 #import "ios/testing/wait_util.h" | |
10 #include "ios/web/public/test/test_web_thread_bundle.h" | |
11 #include "ios/web/public/web_state/web_state_observer.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "testing/gtest_mac.h" | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
Do you need this include?
gambard
2016/12/20 08:54:23
Done.
| |
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_; | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:07
Can you subclass from web::WebTest which already h
gambard
2016/12/20 08:54:22
No the BrowserState is not initialized enough.
Eugene But (OOO till 7-30)
2016/12/20 17:36:18
Can we initialize browser_state_ in WebTest correc
| |
33 std::unique_ptr<TestChromeBrowserState> browser_state_; | |
34 bool web_state_destroyed_; | |
35 }; | |
36 | |
37 // Observer for the test. | |
38 class FaviconWebStateDispatcherObserverTest : public web::WebStateObserver { | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
Should this be TestFaviconWebStateDispatcherObserv
gambard
2016/12/20 08:54:23
Done.
| |
39 public: | |
40 FaviconWebStateDispatcherObserverTest(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 = | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
This looks like a leak. Do you want to use stack d
gambard
2016/12/20 08:54:23
Done.
| |
54 new FaviconWebStateDispatcherImpl(GetBrowserState()); | |
55 web::WebState* webState = dispatcher->RequestWebState(); | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
s/webState/web_state
gambard
2016/12/20 08:54:23
Done.
| |
56 | |
57 favicon::WebFaviconDriver* driver = | |
58 favicon::WebFaviconDriver::FromWebState(webState); | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:07
Do you want to test that history and bookmarks ser
gambard
2016/12/20 08:54:23
History and Bookmarks are attached to the favicon
| |
59 EXPECT_NE(driver, nullptr); | |
60 } | |
61 | |
62 // Tests that the WebState returned will be destroyed after a delay. | |
63 TEST_F(FaviconWebStateDispatcherTest, ReturnWebState) { | |
64 FaviconWebStateDispatcherImpl* dispatcher = | |
65 new FaviconWebStateDispatcherImpl(GetBrowserState(), 0); | |
66 web::WebState* webState = dispatcher->RequestWebState(); | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
s/webState/web_state
gambard
2016/12/20 08:54:23
Done.
| |
67 | |
68 std::unique_ptr<FaviconWebStateDispatcherObserverTest> observer = | |
69 base::MakeUnique<FaviconWebStateDispatcherObserverTest>(webState, this); | |
70 | |
71 ConditionBlock condition = ^{ | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
Optional nit: consider inlining this block.
gambard
2016/12/20 08:54:23
Acknowledged.
| |
72 return IsWebStateDestroyed(); | |
73 }; | |
74 | |
75 dispatcher->ReturnWebState(webState); | |
76 | |
77 ASSERT_TRUE(testing::WaitUntilConditionOrTimeout(0.5, condition)); | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
How come that 0.5 seconds is enough for WebState d
gambard
2016/12/20 08:54:22
There is a new constructor for the dispatcher wher
| |
78 } | |
79 } | |
Eugene But (OOO till 7-30)
2016/12/19 17:30:06
// namespace dom_distiller
gambard
2016/12/20 08:54:23
Done.
| |
OLD | NEW |