| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Tests that the async framework works. | 83 // Tests that the async framework works. |
| 84 class WebUIBrowserAsyncTest : public WebUIBrowserTest { | 84 class WebUIBrowserAsyncTest : public WebUIBrowserTest { |
| 85 public: | 85 public: |
| 86 // Calls the testDone() function from test_api.js | 86 // Calls the testDone() function from test_api.js |
| 87 void TestDone() { | 87 void TestDone() { |
| 88 RunJavascriptFunction("testDone"); | 88 RunJavascriptFunction("testDone"); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Starts a failing test. | 91 // Starts a failing test. |
| 92 void RunTestFailsAssert() { | 92 void RunTestFailsAssert() { |
| 93 RunJavascriptFunction("runAsync", new base::StringValue("testFailsAssert")); | 93 RunJavascriptFunction("runAsync", new base::Value("testFailsAssert")); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Starts a passing test. | 96 // Starts a passing test. |
| 97 void RunTestPasses() { | 97 void RunTestPasses() { |
| 98 RunJavascriptFunction("runAsync", new base::StringValue("testPasses")); | 98 RunJavascriptFunction("runAsync", new base::Value("testPasses")); |
| 99 } | 99 } |
| 100 | 100 |
| 101 protected: | 101 protected: |
| 102 WebUIBrowserAsyncTest() {} | 102 WebUIBrowserAsyncTest() {} |
| 103 | 103 |
| 104 // Class to synchronize asynchronous javascript activity with the tests. | 104 // Class to synchronize asynchronous javascript activity with the tests. |
| 105 class AsyncWebUIMessageHandler : public WebUIMessageHandler { | 105 class AsyncWebUIMessageHandler : public WebUIMessageHandler { |
| 106 public: | 106 public: |
| 107 AsyncWebUIMessageHandler() {} | 107 AsyncWebUIMessageHandler() {} |
| 108 | 108 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // Test that assertions fail immediately after assertion fails (no testContinues | 158 // Test that assertions fail immediately after assertion fails (no testContinues |
| 159 // message). (Sync version). | 159 // message). (Sync version). |
| 160 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncOkTestFail) { | 160 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncOkTestFail) { |
| 161 ASSERT_FALSE(RunJavascriptTest("testFailsAssert")); | 161 ASSERT_FALSE(RunJavascriptTest("testFailsAssert")); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Test that assertions fail immediately after assertion fails (no testContinues | 164 // Test that assertions fail immediately after assertion fails (no testContinues |
| 165 // message). (Async version). | 165 // message). (Async version). |
| 166 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsAssert) { | 166 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsAssert) { |
| 167 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); | 167 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); |
| 168 ASSERT_FALSE(RunJavascriptAsyncTest( | 168 ASSERT_FALSE(RunJavascriptAsyncTest("startAsyncTest", |
| 169 "startAsyncTest", new base::StringValue("testFailsAssert"))); | 169 new base::Value("testFailsAssert"))); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Test that expectations continue the function, but fail the test. | 172 // Test that expectations continue the function, but fail the test. |
| 173 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsExpect) { | 173 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncFailsExpect) { |
| 174 ::testing::InSequence s; | 174 ::testing::InSequence s; |
| 175 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 175 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 176 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); | 176 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); |
| 177 ASSERT_FALSE(RunJavascriptAsyncTest( | 177 ASSERT_FALSE(RunJavascriptAsyncTest("startAsyncTest", |
| 178 "startAsyncTest", new base::StringValue("testFailsExpect"))); | 178 new base::Value("testFailsExpect"))); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Test that test continues and passes. (Sync version). | 181 // Test that test continues and passes. (Sync version). |
| 182 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncPasses) { | 182 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestSyncPasses) { |
| 183 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 183 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 184 ASSERT_TRUE(RunJavascriptTest("testPasses")); | 184 ASSERT_TRUE(RunJavascriptTest("testPasses")); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Test that test continues and passes. (Async version). | 187 // Test that test continues and passes. (Async version). |
| 188 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPasses) { | 188 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPasses) { |
| 189 ::testing::InSequence s; | 189 ::testing::InSequence s; |
| 190 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 190 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 191 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) | 191 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) |
| 192 .WillOnce(::testing::InvokeWithoutArgs( | 192 .WillOnce(::testing::InvokeWithoutArgs( |
| 193 this, &WebUIBrowserAsyncTest::TestDone)); | 193 this, &WebUIBrowserAsyncTest::TestDone)); |
| 194 ASSERT_TRUE(RunJavascriptAsyncTest( | 194 ASSERT_TRUE( |
| 195 "startAsyncTest", new base::StringValue("testPasses"))); | 195 RunJavascriptAsyncTest("startAsyncTest", new base::Value("testPasses"))); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Test that two tests pass. | 198 // Test that two tests pass. |
| 199 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassPass) { | 199 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassPass) { |
| 200 ::testing::InSequence s; | 200 ::testing::InSequence s; |
| 201 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 201 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 202 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) | 202 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) |
| 203 .WillOnce(::testing::InvokeWithoutArgs( | 203 .WillOnce(::testing::InvokeWithoutArgs( |
| 204 this, &WebUIBrowserAsyncTest::RunTestPasses)); | 204 this, &WebUIBrowserAsyncTest::RunTestPasses)); |
| 205 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 205 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 206 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) | 206 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) |
| 207 .WillOnce(::testing::InvokeWithoutArgs( | 207 .WillOnce(::testing::InvokeWithoutArgs( |
| 208 this, &WebUIBrowserAsyncTest::TestDone)); | 208 this, &WebUIBrowserAsyncTest::TestDone)); |
| 209 ASSERT_TRUE(RunJavascriptAsyncTest( | 209 ASSERT_TRUE( |
| 210 "startAsyncTest", new base::StringValue("testPasses"))); | 210 RunJavascriptAsyncTest("startAsyncTest", new base::Value("testPasses"))); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Test that first test passes; second fails. | 213 // Test that first test passes; second fails. |
| 214 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassThenFail) { | 214 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncPassThenFail) { |
| 215 ::testing::InSequence s; | 215 ::testing::InSequence s; |
| 216 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 216 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 217 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) | 217 EXPECT_CALL(message_handler_, HandleTestPasses(::testing::_)) |
| 218 .WillOnce(::testing::InvokeWithoutArgs( | 218 .WillOnce(::testing::InvokeWithoutArgs( |
| 219 this, &WebUIBrowserAsyncTest::RunTestFailsAssert)); | 219 this, &WebUIBrowserAsyncTest::RunTestFailsAssert)); |
| 220 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); | 220 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); |
| 221 ASSERT_FALSE(RunJavascriptAsyncTest( | 221 ASSERT_FALSE( |
| 222 "startAsyncTest", new base::StringValue("testPasses"))); | 222 RunJavascriptAsyncTest("startAsyncTest", new base::Value("testPasses"))); |
| 223 } | 223 } |
| 224 | 224 |
| 225 // Test that testDone() with failure first then sync pass still fails. | 225 // Test that testDone() with failure first then sync pass still fails. |
| 226 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncDoneFailFirstSyncPass) { | 226 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestAsyncDoneFailFirstSyncPass) { |
| 227 ::testing::InSequence s; | 227 ::testing::InSequence s; |
| 228 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); | 228 EXPECT_CALL(message_handler_, HandleTestContinues(::testing::_)); |
| 229 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); | 229 EXPECT_CALL(message_handler_, HandleTestFails(::testing::_)); |
| 230 | 230 |
| 231 // Call runAsync directly instead of deferring through startAsyncTest. It will | 231 // Call runAsync directly instead of deferring through startAsyncTest. It will |
| 232 // call testDone() on failure, then return. | 232 // call testDone() on failure, then return. |
| 233 ASSERT_FALSE(RunJavascriptAsyncTest( | 233 ASSERT_FALSE(RunJavascriptAsyncTest( |
| 234 "runAsync", new base::StringValue("testAsyncDoneFailFirstSyncPass"))); | 234 "runAsync", new base::Value("testAsyncDoneFailFirstSyncPass"))); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Test that calling testDone during RunJavascriptAsyncTest still completes | 237 // Test that calling testDone during RunJavascriptAsyncTest still completes |
| 238 // when waiting for async result. This is similar to the previous test, but call | 238 // when waiting for async result. This is similar to the previous test, but call |
| 239 // testDone directly and expect pass result. | 239 // testDone directly and expect pass result. |
| 240 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 240 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 241 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 241 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 242 } | 242 } |
| 243 | 243 |
| 244 // Test that calling testDone during RunJavascriptTest still completes when | 244 // Test that calling testDone during RunJavascriptTest still completes when |
| 245 // waiting for async result. | 245 // waiting for async result. |
| 246 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 246 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 247 ASSERT_TRUE(RunJavascriptTest("testDone")); | 247 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 248 } | 248 } |
| OLD | NEW |