Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1033)

Side by Side Diff: webkit/database/database_connections_unittest.cc

Issue 14520026: webkit: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 7 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/threading/thread.h" 7 #include "base/threading/thread.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/database/database_connections.h" 10 #include "webkit/database/database_connections.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 EXPECT_FALSE(connections.AddConnection(kOriginId, kName)); 93 EXPECT_FALSE(connections.AddConnection(kOriginId, kName));
94 EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName)); 94 EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName));
95 EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName)); 95 EXPECT_FALSE(connections.RemoveConnection(kOriginId, kName));
96 EXPECT_TRUE(connections.RemoveConnection(kOriginId, kName)); 96 EXPECT_TRUE(connections.RemoveConnection(kOriginId, kName));
97 } 97 }
98 98
99 TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) { 99 TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) {
100 const base::string16 kOriginId(ASCIIToUTF16("origin_id")); 100 const base::string16 kOriginId(ASCIIToUTF16("origin_id"));
101 const base::string16 kName(ASCIIToUTF16("database_name")); 101 const base::string16 kName(ASCIIToUTF16("database_name"));
102 102
103 MessageLoop message_loop; 103 base::MessageLoop message_loop;
104 scoped_refptr<DatabaseConnectionsWrapper> obj( 104 scoped_refptr<DatabaseConnectionsWrapper> obj(new DatabaseConnectionsWrapper);
105 new DatabaseConnectionsWrapper);
106 EXPECT_FALSE(obj->HasOpenConnections()); 105 EXPECT_FALSE(obj->HasOpenConnections());
107 obj->AddOpenConnection(kOriginId, kName); 106 obj->AddOpenConnection(kOriginId, kName);
108 EXPECT_TRUE(obj->HasOpenConnections()); 107 EXPECT_TRUE(obj->HasOpenConnections());
109 obj->AddOpenConnection(kOriginId, kName); 108 obj->AddOpenConnection(kOriginId, kName);
110 EXPECT_TRUE(obj->HasOpenConnections()); 109 EXPECT_TRUE(obj->HasOpenConnections());
111 obj->RemoveOpenConnection(kOriginId, kName); 110 obj->RemoveOpenConnection(kOriginId, kName);
112 EXPECT_TRUE(obj->HasOpenConnections()); 111 EXPECT_TRUE(obj->HasOpenConnections());
113 obj->RemoveOpenConnection(kOriginId, kName); 112 obj->RemoveOpenConnection(kOriginId, kName);
114 EXPECT_FALSE(obj->HasOpenConnections()); 113 EXPECT_FALSE(obj->HasOpenConnections());
115 obj->WaitForAllDatabasesToClose(); // should return immediately 114 obj->WaitForAllDatabasesToClose(); // should return immediately
116 115
117 // Test WaitForAllDatabasesToClose with the last connection 116 // Test WaitForAllDatabasesToClose with the last connection
118 // being removed on the current thread. 117 // being removed on the current thread.
119 obj->AddOpenConnection(kOriginId, kName); 118 obj->AddOpenConnection(kOriginId, kName);
120 bool did_task_execute = false; 119 bool did_task_execute = false;
121 MessageLoop::current()->PostTask( 120 base::MessageLoop::current()->PostTask(
122 FROM_HERE, 121 FROM_HERE,
123 base::Bind(&RemoveConnectionTask, kOriginId, kName, obj, 122 base::Bind(
124 &did_task_execute)); 123 &RemoveConnectionTask, kOriginId, kName, obj, &did_task_execute));
125 obj->WaitForAllDatabasesToClose(); // should return after the task executes 124 obj->WaitForAllDatabasesToClose(); // should return after the task executes
126 EXPECT_TRUE(did_task_execute); 125 EXPECT_TRUE(did_task_execute);
127 EXPECT_FALSE(obj->HasOpenConnections()); 126 EXPECT_FALSE(obj->HasOpenConnections());
128 127
129 // Test WaitForAllDatabasesToClose with the last connection 128 // Test WaitForAllDatabasesToClose with the last connection
130 // being removed on another thread. 129 // being removed on another thread.
131 obj->AddOpenConnection(kOriginId, kName); 130 obj->AddOpenConnection(kOriginId, kName);
132 base::Thread thread("WrapperTestThread"); 131 base::Thread thread("WrapperTestThread");
133 thread.Start(); 132 thread.Start();
134 did_task_execute = false; 133 did_task_execute = false;
135 MessageLoop::current()->PostTask( 134 base::MessageLoop::current()->PostTask(
136 FROM_HERE, 135 FROM_HERE,
137 base::Bind(&ScheduleRemoveConnectionTask, &thread, kOriginId, kName, obj, 136 base::Bind(&ScheduleRemoveConnectionTask,
brettw 2013/05/06 17:43:33 I think the old style was fine.
xhwang 2013/05/07 00:11:07 Done.
137 &thread,
138 kOriginId,
139 kName,
140 obj,
138 &did_task_execute)); 141 &did_task_execute));
139 obj->WaitForAllDatabasesToClose(); // should return after the task executes 142 obj->WaitForAllDatabasesToClose(); // should return after the task executes
140 EXPECT_TRUE(did_task_execute); 143 EXPECT_TRUE(did_task_execute);
141 EXPECT_FALSE(obj->HasOpenConnections()); 144 EXPECT_FALSE(obj->HasOpenConnections());
142 } 145 }
143 146
144 } // namespace webkit_database 147 } // namespace webkit_database
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698