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 "chrome/test/ppapi/ppapi_test.h" | 5 #include "chrome/test/ppapi/ppapi_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | |
10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
11 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
13 #include "base/test/test_timeouts.h" | |
14 #include "build/build_config.h" | |
15 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
17 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
18 #include "chrome/browser/infobars/infobar.h" | 15 #include "chrome/browser/infobars/infobar.h" |
19 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_tabstrip.h" | |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/test/base/test_switches.h" | 21 #include "chrome/test/base/test_switches.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
27 #include "content/public/browser/dom_operation_notification_details.h" | 23 #include "content/public/browser/dom_operation_notification_details.h" |
28 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_types.h" | |
30 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/content_paths.h" | |
32 #include "content/public/common/content_switches.h" | |
33 #include "content/public/test/browser_test_utils.h" | |
34 #include "content/public/test/test_renderer_host.h" | |
35 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
36 #include "net/base/test_data_directory.h" | 27 #include "net/base/test_data_directory.h" |
37 #include "ppapi/shared_impl/ppapi_switches.h" | 28 #include "ppapi/shared_impl/ppapi_switches.h" |
38 #include "ui/gl/gl_switches.h" | 29 #include "ui/gl/gl_switches.h" |
39 | 30 |
40 using content::DomOperationNotificationDetails; | 31 using content::DomOperationNotificationDetails; |
41 using content::RenderViewHost; | 32 using content::RenderViewHost; |
42 | 33 |
43 namespace { | 34 namespace { |
44 | 35 |
(...skipping 21 matching lines...) Expand all Loading... |
66 message_ = trimmed; | 57 message_ = trimmed; |
67 return DONE; | 58 return DONE; |
68 } | 59 } |
69 } | 60 } |
70 | 61 |
71 void PPAPITestMessageHandler::Reset() { | 62 void PPAPITestMessageHandler::Reset() { |
72 TestMessageHandler::Reset(); | 63 TestMessageHandler::Reset(); |
73 message_.clear(); | 64 message_.clear(); |
74 } | 65 } |
75 | 66 |
76 PPAPITestBase::InfoBarObserver::InfoBarObserver() { | 67 PPAPITestBase::InfoBarObserver::InfoBarObserver(PPAPITestBase* test_base) |
| 68 : test_base_(test_base), |
| 69 expecting_infobar_(false), |
| 70 should_accept_(false) { |
77 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 71 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
78 content::NotificationService::AllSources()); | 72 content::NotificationService::AllSources()); |
79 } | 73 } |
80 | 74 |
81 PPAPITestBase::InfoBarObserver::~InfoBarObserver() { | 75 PPAPITestBase::InfoBarObserver::~InfoBarObserver() { |
82 EXPECT_EQ(0u, expected_infobars_.size()) << "Missing an expected infobar"; | 76 EXPECT_FALSE(expecting_infobar_) << "Missing an expected infobar"; |
| 77 } |
| 78 |
| 79 void PPAPITestBase::InfoBarObserver::ExpectInfoBarAndAccept( |
| 80 bool should_accept) { |
| 81 ASSERT_FALSE(expecting_infobar_); |
| 82 expecting_infobar_ = true; |
| 83 should_accept_ = should_accept; |
83 } | 84 } |
84 | 85 |
85 void PPAPITestBase::InfoBarObserver::Observe( | 86 void PPAPITestBase::InfoBarObserver::Observe( |
86 int type, | 87 int type, |
87 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
88 const content::NotificationDetails& details) { | 89 const content::NotificationDetails& details) { |
89 ASSERT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); | 90 ASSERT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); |
90 InfoBarDelegate* infobar = | 91 // It's not safe to remove the infobar here, since other observers (e.g. the |
91 content::Details<InfoBarAddedDetails>(details).ptr(); | 92 // InfoBarContainer) may still need to access it. Instead, post a task to |
92 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 93 // do all necessary infobar manipulation as soon as this call stack returns. |
93 infobar->AsConfirmInfoBarDelegate(); | 94 base::MessageLoop::current()->PostTask( |
94 ASSERT_TRUE(confirm_infobar_delegate); | 95 FROM_HERE, base::Bind(&InfoBarObserver::VerifyInfoBarState, |
95 | 96 base::Unretained(this))); |
96 ASSERT_FALSE(expected_infobars_.empty()) << "Unexpected infobar"; | |
97 if (expected_infobars_.front()) | |
98 confirm_infobar_delegate->Accept(); | |
99 else | |
100 confirm_infobar_delegate->Cancel(); | |
101 expected_infobars_.pop_front(); | |
102 | |
103 // TODO(bauerb): We should close the infobar. | |
104 } | 97 } |
105 | 98 |
106 void PPAPITestBase::InfoBarObserver::ExpectInfoBarAndAccept( | 99 void PPAPITestBase::InfoBarObserver::VerifyInfoBarState() { |
107 bool should_accept) { | 100 content::WebContents* web_contents = |
108 expected_infobars_.push_back(should_accept); | 101 test_base_->browser()->tab_strip_model()->GetActiveWebContents(); |
| 102 ASSERT_TRUE(web_contents != NULL); |
| 103 InfoBarService* infobar_service = |
| 104 InfoBarService::FromWebContents(web_contents); |
| 105 ASSERT_TRUE(infobar_service != NULL); |
| 106 |
| 107 EXPECT_EQ(expecting_infobar_ ? 1U : 0U, infobar_service->infobar_count()); |
| 108 if (!expecting_infobar_) |
| 109 return; |
| 110 expecting_infobar_ = false; |
| 111 |
| 112 InfoBar* infobar = infobar_service->infobar_at(0); |
| 113 ConfirmInfoBarDelegate* delegate = |
| 114 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 115 ASSERT_TRUE(delegate != NULL); |
| 116 if (should_accept_) |
| 117 delegate->Accept(); |
| 118 else |
| 119 delegate->Cancel(); |
| 120 |
| 121 infobar_service->RemoveInfoBar(infobar); |
109 } | 122 } |
110 | 123 |
111 PPAPITestBase::PPAPITestBase() { | 124 PPAPITestBase::PPAPITestBase() { |
112 } | 125 } |
113 | 126 |
114 void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) { | 127 void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) { |
115 // The test sends us the result via a cookie. | 128 // The test sends us the result via a cookie. |
116 command_line->AppendSwitch(switches::kEnableFileCookies); | 129 command_line->AppendSwitch(switches::kEnableFileCookies); |
117 | 130 |
118 // Some stuff is hung off of the testing interface which is not enabled | 131 // Some stuff is hung off of the testing interface which is not enabled |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 const std::string& base, | 383 const std::string& base, |
371 const std::string& test_case) { | 384 const std::string& test_case) { |
372 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), | 385 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), |
373 test_case.c_str()); | 386 test_case.c_str()); |
374 } | 387 } |
375 | 388 |
376 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { | 389 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { |
377 // The default content setting for the PPAPI broker is ASK. We purposefully | 390 // The default content setting for the PPAPI broker is ASK. We purposefully |
378 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. | 391 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. |
379 } | 392 } |
OLD | NEW |