Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/external_protocol/external_protocol_handler_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/external_protocol/external_protocol_handler.h" 5 #include "chrome/browser/external_protocol/external_protocol_handler.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "content/public/test/test_browser_thread.h" 8 #include "content/public/test/test_browser_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 has_prompted_ = true; 67 has_prompted_ = true;
68 } 68 }
69 69
70 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) OVERRIDE { 70 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) OVERRIDE {
71 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK); 71 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK);
72 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); 72 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT);
73 has_launched_ = true; 73 has_launched_ = true;
74 } 74 }
75 75
76 virtual void FinishedProcessingCheck() OVERRIDE { 76 virtual void FinishedProcessingCheck() OVERRIDE {
77 MessageLoop::current()->Quit(); 77 base::MessageLoop::current()->Quit();
78 } 78 }
79 79
80 void set_os_state(ShellIntegration::DefaultWebClientState value) { 80 void set_os_state(ShellIntegration::DefaultWebClientState value) {
81 os_state_ = value; 81 os_state_ = value;
82 } 82 }
83 83
84 void set_block_state(ExternalProtocolHandler::BlockState value) { 84 void set_block_state(ExternalProtocolHandler::BlockState value) {
85 block_state_ = value; 85 block_state_ = value;
86 } 86 }
87 87
88 bool has_launched() { return has_launched_; } 88 bool has_launched() { return has_launched_; }
89 bool has_prompted() { return has_prompted_; } 89 bool has_prompted() { return has_prompted_; }
90 bool has_blocked() { return has_blocked_; } 90 bool has_blocked() { return has_blocked_; }
91 91
92 private: 92 private:
93 ExternalProtocolHandler::BlockState block_state_; 93 ExternalProtocolHandler::BlockState block_state_;
94 ShellIntegration::DefaultWebClientState os_state_; 94 ShellIntegration::DefaultWebClientState os_state_;
95 bool has_launched_; 95 bool has_launched_;
96 bool has_prompted_; 96 bool has_prompted_;
97 bool has_blocked_; 97 bool has_blocked_;
98 }; 98 };
99 99
100 class ExternalProtocolHandlerTest : public testing::Test { 100 class ExternalProtocolHandlerTest : public testing::Test {
101 protected: 101 protected:
102 ExternalProtocolHandlerTest() 102 ExternalProtocolHandlerTest()
103 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 103 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
104 file_thread_(BrowserThread::FILE) {} 104 file_thread_(BrowserThread::FILE) {}
105 105
106 virtual void SetUp() { 106 virtual void SetUp() {
107 file_thread_.Start(); 107 file_thread_.Start();
108 } 108 }
109 109
110 virtual void TearDown() { 110 virtual void TearDown() {
111 // Ensure that g_accept_requests gets set back to true after test execution. 111 // Ensure that g_accept_requests gets set back to true after test execution.
112 ExternalProtocolHandler::PermitLaunchUrl(); 112 ExternalProtocolHandler::PermitLaunchUrl();
113 } 113 }
114 114
115 void DoTest(ExternalProtocolHandler::BlockState block_state, 115 void DoTest(ExternalProtocolHandler::BlockState block_state,
116 ShellIntegration::DefaultWebClientState os_state, 116 ShellIntegration::DefaultWebClientState os_state,
117 bool should_prompt, bool should_launch, bool should_block) { 117 bool should_prompt, bool should_launch, bool should_block) {
118 GURL url("mailto:test@test.com"); 118 GURL url("mailto:test@test.com");
119 ASSERT_FALSE(delegate_.has_prompted()); 119 ASSERT_FALSE(delegate_.has_prompted());
120 ASSERT_FALSE(delegate_.has_launched()); 120 ASSERT_FALSE(delegate_.has_launched());
121 ASSERT_FALSE(delegate_.has_blocked()); 121 ASSERT_FALSE(delegate_.has_blocked());
122 122
123 delegate_.set_block_state(block_state); 123 delegate_.set_block_state(block_state);
124 delegate_.set_os_state(os_state); 124 delegate_.set_os_state(os_state);
125 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_); 125 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_);
126 if (block_state != ExternalProtocolHandler::BLOCK) 126 if (block_state != ExternalProtocolHandler::BLOCK)
127 MessageLoop::current()->Run(); 127 base::MessageLoop::current()->Run();
128 128
129 ASSERT_EQ(should_prompt, delegate_.has_prompted()); 129 ASSERT_EQ(should_prompt, delegate_.has_prompted());
130 ASSERT_EQ(should_launch, delegate_.has_launched()); 130 ASSERT_EQ(should_launch, delegate_.has_launched());
131 ASSERT_EQ(should_block, delegate_.has_blocked()); 131 ASSERT_EQ(should_block, delegate_.has_blocked());
132 } 132 }
133 133
134 MessageLoopForUI ui_message_loop_; 134 base::MessageLoopForUI ui_message_loop_;
135 content::TestBrowserThread ui_thread_; 135 content::TestBrowserThread ui_thread_;
136 content::TestBrowserThread file_thread_; 136 content::TestBrowserThread file_thread_;
137 137
138 FakeExternalProtocolHandlerDelegate delegate_; 138 FakeExternalProtocolHandlerDelegate delegate_;
139 }; 139 };
140 140
141 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) { 141 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) {
142 DoTest(ExternalProtocolHandler::BLOCK, 142 DoTest(ExternalProtocolHandler::BLOCK,
143 ShellIntegration::IS_DEFAULT, 143 ShellIntegration::IS_DEFAULT,
144 false, false, true); 144 false, false, true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 DoTest(ExternalProtocolHandler::UNKNOWN, 184 DoTest(ExternalProtocolHandler::UNKNOWN,
185 ShellIntegration::NOT_DEFAULT, 185 ShellIntegration::NOT_DEFAULT,
186 true, false, false); 186 true, false, false);
187 } 187 }
188 188
189 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { 189 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) {
190 DoTest(ExternalProtocolHandler::UNKNOWN, 190 DoTest(ExternalProtocolHandler::UNKNOWN,
191 ShellIntegration::UNKNOWN_DEFAULT, 191 ShellIntegration::UNKNOWN_DEFAULT,
192 true, false, false); 192 true, false, false);
193 } 193 }
OLDNEW
« no previous file with comments | « chrome/browser/external_protocol/external_protocol_handler.cc ('k') | chrome/browser/feedback/feedback_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698