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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
| 7 #include "base/run_loop.h" |
7 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
8 #include "chrome/renderer/content_settings_observer.h" | 9 #include "chrome/renderer/content_settings_observer.h" |
9 #include "chrome/test/base/chrome_render_view_test.h" | 10 #include "chrome/test/base/chrome_render_view_test.h" |
10 #include "components/content_settings/core/common/content_settings.h" | 11 #include "components/content_settings/core/common/content_settings.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 16 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
16 #include "third_party/WebKit/public/web/WebView.h" | 17 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 108 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
108 ContentSettingsPattern::Wildcard(), | 109 ContentSettingsPattern::Wildcard(), |
109 CONTENT_SETTING_BLOCK, | 110 CONTENT_SETTING_BLOCK, |
110 std::string(), | 111 std::string(), |
111 false)); | 112 false)); |
112 ContentSettingsObserver* observer = ContentSettingsObserver::Get( | 113 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
113 view_->GetMainRenderFrame()); | 114 view_->GetMainRenderFrame()); |
114 observer->SetContentSettingRules(&content_setting_rules); | 115 observer->SetContentSettingRules(&content_setting_rules); |
115 | 116 |
116 // Make sure no pending messages are in the queue. | 117 // Make sure no pending messages are in the queue. |
117 ProcessPendingMessages(); | 118 base::RunLoop().RunUntilIdle(); |
118 render_thread_->sink().ClearMessages(); | 119 render_thread_->sink().ClearMessages(); |
119 | 120 |
120 // 3. Reload page. | 121 // 3. Reload page. |
121 std::string url_str = "data:text/html;charset=utf-8,"; | 122 std::string url_str = "data:text/html;charset=utf-8,"; |
122 url_str.append(kHtml); | 123 url_str.append(kHtml); |
123 GURL url(url_str); | 124 GURL url(url_str); |
124 Reload(url); | 125 Reload(url); |
125 ProcessPendingMessages(); | 126 base::RunLoop().RunUntilIdle(); |
126 | 127 |
127 // 4. Verify that the notification that javascript was blocked is sent after | 128 // 4. Verify that the notification that javascript was blocked is sent after |
128 // the navigation notification is sent. | 129 // the navigation notification is sent. |
129 int navigation_index = -1; | 130 int navigation_index = -1; |
130 int block_index = -1; | 131 int block_index = -1; |
131 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { | 132 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { |
132 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); | 133 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); |
133 if (msg->type() == GetNavigationIPCType()) | 134 if (msg->type() == GetNavigationIPCType()) |
134 navigation_index = i; | 135 navigation_index = i; |
135 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) | 136 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 ContentSettingPatternSource( | 517 ContentSettingPatternSource( |
517 ContentSettingsPattern::Wildcard(), | 518 ContentSettingsPattern::Wildcard(), |
518 ContentSettingsPattern::Wildcard(), | 519 ContentSettingsPattern::Wildcard(), |
519 CONTENT_SETTING_BLOCK, | 520 CONTENT_SETTING_BLOCK, |
520 std::string(), | 521 std::string(), |
521 false)); | 522 false)); |
522 | 523 |
523 EXPECT_FALSE(observer->AllowAutoplay(true)); | 524 EXPECT_FALSE(observer->AllowAutoplay(true)); |
524 ::testing::Mock::VerifyAndClearExpectations(&observer); | 525 ::testing::Mock::VerifyAndClearExpectations(&observer); |
525 } | 526 } |
OLD | NEW |