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