Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 function WebUIAssertionsTest() {} | |
| 6 | |
| 7 WebUIAssertionsTest.prototype = { | |
| 8 __proto__: testing.Test.prototype, | |
| 9 browsePreload: 'chrome://DummyURL', | |
| 10 typedefCppFixture: null, | |
| 11 }; | |
| 12 | |
| 13 GEN('#include "chrome/browser/ui/webui/chrome_web_ui.h"'); | |
|
Paweł Hajdan Jr.
2011/07/20 16:58:49
I don't really like how C++ and JS code is mixed i
Sheridan Rawlins
2011/07/21 02:05:27
In getting the generator to work, we didn't want t
| |
| 14 GEN('#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"'); | |
| 15 GEN('#include "googleurl/src/gurl.h"'); | |
| 16 GEN('#include "testing/gmock/include/gmock/gmock.h"'); | |
| 17 GEN(''); | |
| 18 GEN('using ::testing::_;'); | |
| 19 GEN('using ::testing::Eq;'); | |
| 20 GEN('using ::testing::StrictMock;'); | |
| 21 GEN(''); | |
| 22 GEN('// Dummy URL location for us to override.'); | |
| 23 GEN('const char kDummyURL[] = "chrome://DummyURL/";'); | |
| 24 GEN(''); | |
| 25 GEN('// Returns a new WebUI object for the TabContents from |arg0|.'); | |
| 26 GEN('ACTION(ReturnNewWebUI) {'); | |
| 27 GEN(' return new ChromeWebUI(arg0);'); | |
| 28 GEN('}'); | |
| 29 GEN(''); | |
| 30 GEN('// Mock the TestChromeWebUIFactory::WebUIProvider to prove that ' + | |
| 31 'we are called as'); | |
| 32 GEN('// expected.'); | |
| 33 GEN('class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider {'); | |
| 34 GEN(' public:'); | |
| 35 GEN(' MOCK_METHOD2(NewWebUI, WebUI*(TabContents* tab_contents, const GURL& ' + | |
| 36 'url));'); | |
| 37 GEN('};'); | |
| 38 GEN(''); | |
| 39 GEN('class WebUIAssertionsTest : public WebUIBrowserTest {'); | |
| 40 GEN(' public:'); | |
| 41 GEN(' virtual void SetUpOnMainThread() OVERRIDE {'); | |
| 42 GEN(' WebUIBrowserTest::SetUpOnMainThread();'); | |
| 43 GEN(' TestChromeWebUIFactory::AddFactoryOverride('); | |
| 44 GEN(' GURL(kDummyURL).host(), &mock_provider_);'); | |
| 45 GEN(' EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(GURL(kDummyURL))))'); | |
| 46 GEN(' .WillOnce(ReturnNewWebUI());'); | |
| 47 GEN(' }'); | |
| 48 GEN(' virtual void CleanUpOnMainThread() OVERRIDE {'); | |
| 49 GEN(' WebUIBrowserTest::CleanUpOnMainThread();'); | |
| 50 GEN(' TestChromeWebUIFactory::RemoveFactoryOverride('); | |
| 51 GEN(' GURL(kDummyURL).host());'); | |
| 52 GEN(' }'); | |
| 53 GEN(''); | |
| 54 GEN(' StrictMock<MockWebUIProvider> mock_provider_;'); | |
| 55 GEN(''); | |
| 56 GEN('};'); | |
| 57 | |
| 58 TEST_F('WebUIAssertionsTest', 'testTwoExpects', function() { | |
| 59 var result = runTest( | |
| 60 function() { | |
| 61 expectTrue(false); | |
| 62 expectTrue(0); | |
| 63 }, []); | |
| 64 | |
| 65 expectFalse(result[0]); | |
| 66 expectTrue(!!result[1].match(/expectTrue\(false\): false/)); | |
| 67 expectTrue(!!result[1].match(/expectTrue\(0\): 0/)); | |
| 68 }); | |
| 69 | |
| 70 function twoExpects() { | |
| 71 expectTrue(false, 'message1'); | |
| 72 expectTrue(false, 'message2'); | |
| 73 } | |
| 74 | |
| 75 TEST_F('WebUIAssertionsTest', 'testCallTestTwice', function() { | |
| 76 var result = runTest( | |
| 77 function() { | |
| 78 twoExpects(); | |
| 79 twoExpects(); | |
| 80 }, []); | |
| 81 expectFalse(result[0]); | |
| 82 expectEquals( | |
| 83 2, result[1].match(/expectTrue\(false, 'message1'\): false/g).length); | |
| 84 expectEquals( | |
| 85 2, result[1].match(/expectTrue\(false, 'message2'\): false/g).length); | |
| 86 }); | |
| OLD | NEW |