OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/gfx/rect.h" | 6 #include "base/gfx/rect.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/automation/extension_automation_constants.h" | 10 #include "chrome/browser/automation/extension_automation_constants.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 functions_enabled_.push_back("*"); | 48 functions_enabled_.push_back("*"); |
49 } | 49 } |
50 | 50 |
51 void set_functions_enabled( | 51 void set_functions_enabled( |
52 const std::vector<std::string>& functions_enabled) { | 52 const std::vector<std::string>& functions_enabled) { |
53 functions_enabled_ = functions_enabled; | 53 functions_enabled_ = functions_enabled; |
54 } | 54 } |
55 | 55 |
56 void SetUp() { | 56 void SetUp() { |
57 ParentTestType::SetUp(); | 57 ParentTestType::SetUp(); |
58 automation()->SetEnableExtensionAutomation(functions_enabled_); | 58 |
| 59 AutomationProxyForExternalTab* proxy = |
| 60 static_cast<AutomationProxyForExternalTab*>(automation()); |
| 61 HWND external_tab_container = NULL; |
| 62 HWND tab_wnd = NULL; |
| 63 tab_ = proxy->CreateTabWithHostWindow(false, |
| 64 GURL(), &external_tab_container, &tab_wnd); |
| 65 |
| 66 tab_->SetEnableExtensionAutomation(functions_enabled_); |
59 } | 67 } |
60 | 68 |
61 void TearDown() { | 69 void TearDown() { |
62 automation()->SetEnableExtensionAutomation(std::vector<std::string>()); | 70 tab_->SetEnableExtensionAutomation(std::vector<std::string>()); |
| 71 |
| 72 AutomationProxyForExternalTab* proxy = |
| 73 static_cast<AutomationProxyForExternalTab*>(automation()); |
| 74 proxy->DestroyHostWindow(); |
| 75 proxy->WaitForTabCleanup(tab_, action_max_timeout_ms()); |
| 76 EXPECT_FALSE(tab_->is_valid()); |
| 77 tab_.release(); |
| 78 |
63 ParentTestType::TearDown(); | 79 ParentTestType::TearDown(); |
64 } | 80 } |
65 | 81 |
66 void TestWithURL(const GURL& url) { | 82 void TestWithURL(const GURL& url) { |
67 AutomationProxyForExternalTab* proxy = | 83 EXPECT_TRUE(tab_->is_valid()); |
| 84 if (tab_) { |
| 85 AutomationProxyForExternalTab* proxy = |
68 static_cast<AutomationProxyForExternalTab*>(automation()); | 86 static_cast<AutomationProxyForExternalTab*>(automation()); |
69 HWND external_tab_container = NULL; | |
70 HWND tab_wnd = NULL; | |
71 scoped_refptr<TabProxy> tab(proxy->CreateTabWithHostWindow(false, | |
72 GURL(), &external_tab_container, &tab_wnd)); | |
73 | 87 |
74 EXPECT_TRUE(tab->is_valid()); | |
75 if (tab) { | |
76 // Enter a message loop to allow the tab to be created | 88 // Enter a message loop to allow the tab to be created |
77 proxy->WaitForNavigation(2000); | 89 proxy->WaitForNavigation(2000); |
78 DoAdditionalPreNavigateSetup(tab.get()); | 90 DoAdditionalPreNavigateSetup(tab_.get()); |
79 | 91 |
80 // We explicitly do not make this a toolstrip in the extension manifest, | 92 // We explicitly do not make this a toolstrip in the extension manifest, |
81 // so that the test can control when it gets loaded, and so that we test | 93 // so that the test can control when it gets loaded, and so that we test |
82 // the intended behavior that tabs should be able to show extension pages | 94 // the intended behavior that tabs should be able to show extension pages |
83 // (useful for development etc.) | 95 // (useful for development etc.) |
84 tab->NavigateInExternalTab(url, GURL()); | 96 tab_->NavigateInExternalTab(url, GURL()); |
85 EXPECT_TRUE(proxy->WaitForMessage(action_max_timeout_ms())); | 97 EXPECT_TRUE(proxy->WaitForMessage(action_max_timeout_ms())); |
86 | |
87 proxy->DestroyHostWindow(); | |
88 proxy->WaitForTabCleanup(tab, action_max_timeout_ms()); | |
89 EXPECT_FALSE(tab->is_valid()); | |
90 } | 98 } |
91 } | 99 } |
92 | 100 |
93 // Override if you need additional stuff before we navigate the page. | 101 // Override if you need additional stuff before we navigate the page. |
94 virtual void DoAdditionalPreNavigateSetup(TabProxy* tab) { | 102 virtual void DoAdditionalPreNavigateSetup(TabProxy* tab) { |
95 } | 103 } |
96 | 104 |
97 protected: | 105 protected: |
98 // Extension API functions that we want to take over. Defaults to all. | 106 // Extension API functions that we want to take over. Defaults to all. |
99 std::vector<std::string> functions_enabled_; | 107 std::vector<std::string> functions_enabled_; |
| 108 scoped_refptr<TabProxy> tab_; |
100 | 109 |
101 private: | 110 private: |
102 DISALLOW_COPY_AND_ASSIGN(ExtensionUITest); | 111 DISALLOW_COPY_AND_ASSIGN(ExtensionUITest); |
103 }; | 112 }; |
104 | 113 |
105 // For tests that only need to check for a single postMessage | 114 // For tests that only need to check for a single postMessage |
106 // being received from the tab in Chrome. These tests can send a message | 115 // being received from the tab in Chrome. These tests can send a message |
107 // to the tab before receiving the new message, but there will not be | 116 // to the tab before receiving the new message, but there will not be |
108 // a chance to respond by sending a message from the test to the tab after | 117 // a chance to respond by sending a message from the test to the tab after |
109 // the postMessage is received. | 118 // the postMessage is received. |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 proxy->event_count_.size()); | 522 proxy->event_count_.size()); |
514 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin(); | 523 for (std::map<std::string, int>::iterator i = proxy->event_count_.begin(); |
515 i != proxy->event_count_.end(); ++i) { | 524 i != proxy->event_count_.end(); ++i) { |
516 const std::pair<std::string, int>& value = *i; | 525 const std::pair<std::string, int>& value = *i; |
517 ASSERT_EQ(1, value.second); | 526 ASSERT_EQ(1, value.second); |
518 } | 527 } |
519 } | 528 } |
520 #endif // defined(OS_WIN) | 529 #endif // defined(OS_WIN) |
521 | 530 |
522 } // namespace | 531 } // namespace |
OLD | NEW |