OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/web_contents_tester.h" | 5 #include "content/public/test/web_contents_tester.h" |
6 | 6 |
7 #include "content/browser/web_contents/test_web_contents.h" | 7 #include "content/browser/web_contents/test_web_contents.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // The two subclasses here are instantiated via the deprecated | 13 // The two subclasses here are instantiated via the deprecated |
14 // CreateWebContentsFor... factories below. | 14 // CreateWebContentsFor... factories below. |
15 | 15 |
16 class TestWebContentsCountFocus : public TestWebContents { | 16 class TestWebContentsCountFocus : public TestWebContents { |
17 public: | 17 public: |
18 TestWebContentsCountFocus(content::BrowserContext* browser_context, | 18 explicit TestWebContentsCountFocus(content::BrowserContext* browser_context) |
19 content::SiteInstance* instance) | 19 : TestWebContents(browser_context), focus_called_(0) { |
20 : TestWebContents(browser_context, instance), focus_called_(0) { | |
21 } | 20 } |
22 | 21 |
23 virtual int GetNumberOfFocusCalls() OVERRIDE { | 22 virtual int GetNumberOfFocusCalls() OVERRIDE { |
24 return focus_called_; | 23 return focus_called_; |
25 } | 24 } |
26 | 25 |
27 virtual void Focus() OVERRIDE { | 26 virtual void Focus() OVERRIDE { |
28 focus_called_++; | 27 focus_called_++; |
29 } | 28 } |
30 | 29 |
31 private: | 30 private: |
32 int focus_called_; | 31 int focus_called_; |
33 }; | 32 }; |
34 | 33 |
35 class TestWebContentsCountSetFocusToLocationBar : public TestWebContents { | 34 class TestWebContentsCountSetFocusToLocationBar : public TestWebContents { |
36 public: | 35 public: |
37 TestWebContentsCountSetFocusToLocationBar( | 36 explicit TestWebContentsCountSetFocusToLocationBar( |
38 content::BrowserContext* browser_context, | 37 content::BrowserContext* browser_context) |
39 SiteInstance* instance) | 38 : TestWebContents(browser_context), focus_called_(0) { |
40 : TestWebContents(browser_context, instance), focus_called_(0) { | |
41 } | 39 } |
42 | 40 |
43 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } | 41 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } |
44 virtual int GetNumberOfFocusCalls() OVERRIDE { | 42 virtual int GetNumberOfFocusCalls() OVERRIDE { |
45 return focus_called_; | 43 return focus_called_; |
46 } | 44 } |
47 | 45 |
48 private: | 46 private: |
49 int focus_called_; | 47 int focus_called_; |
50 }; | 48 }; |
51 | 49 |
52 } // namespace | 50 } // namespace |
53 | 51 |
54 // static | 52 // static |
55 WebContentsTester* WebContentsTester::For(WebContents* contents) { | 53 WebContentsTester* WebContentsTester::For(WebContents* contents) { |
56 return static_cast<TestWebContents*>(contents); | 54 return static_cast<TestWebContents*>(contents); |
57 } | 55 } |
58 | 56 |
59 // static | 57 // static |
60 WebContents* WebContentsTester::CreateTestWebContents( | 58 WebContents* WebContentsTester::CreateTestWebContents( |
61 BrowserContext* browser_context, | 59 BrowserContext* browser_context, |
62 SiteInstance* instance) { | 60 SiteInstance* instance) { |
63 return new TestWebContents(browser_context, instance); | 61 return TestWebContents::Create(browser_context, instance); |
64 } | 62 } |
65 | 63 |
66 // static | 64 // static |
67 WebContents* WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( | 65 WebContents* WebContentsTester::CreateTestWebContentsCountSetFocusToLocationBar( |
68 BrowserContext* browser_context, | 66 BrowserContext* browser_context, |
69 SiteInstance* instance) { | 67 SiteInstance* instance) { |
70 return new TestWebContentsCountSetFocusToLocationBar( | 68 TestWebContentsCountSetFocusToLocationBar* web_contents = |
71 browser_context, instance); | 69 new TestWebContentsCountSetFocusToLocationBar(browser_context); |
| 70 web_contents->Init(browser_context, instance, MSG_ROUTING_NONE, NULL); |
| 71 return web_contents; |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 WebContents* WebContentsTester::CreateTestWebContentsCountFocus( | 75 WebContents* WebContentsTester::CreateTestWebContentsCountFocus( |
76 BrowserContext* browser_context, | 76 BrowserContext* browser_context, |
77 SiteInstance* instance) { | 77 SiteInstance* instance) { |
78 return new TestWebContentsCountFocus(browser_context, instance); | 78 TestWebContentsCountFocus* web_contents = |
| 79 new TestWebContentsCountFocus(browser_context); |
| 80 web_contents->Init(browser_context, instance, MSG_ROUTING_NONE, NULL); |
| 81 return web_contents; |
79 } | 82 } |
80 | 83 |
81 } // namespace content | 84 } // namespace content |
OLD | NEW |