|
1 /* |
|
2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
|
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
|
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|
23 * THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #include "TestController.h" |
|
27 |
|
28 #include "PlatformWebView.h" |
|
29 #include "TestInvocation.h" |
|
30 #include <WebKit2/WKContextPrivate.h> |
|
31 |
|
32 namespace WTR { |
|
33 |
|
34 TestController& TestController::shared() |
|
35 { |
|
36 static TestController& shared = *new TestController; |
|
37 return shared; |
|
38 } |
|
39 |
|
40 TestController::TestController() |
|
41 : m_dumpPixels(false) |
|
42 , m_verbose(false) |
|
43 , m_printSeparators(false) |
|
44 , m_usingServerMode(false) |
|
45 { |
|
46 } |
|
47 |
|
48 void TestController::initialize(int argc, const char* argv[]) |
|
49 { |
|
50 platformInitialize(); |
|
51 |
|
52 for (int i = 1; i < argc; ++i) { |
|
53 std::string argument(argv[i]); |
|
54 |
|
55 if (argument == "--pixel-tests") { |
|
56 m_dumpPixels = true; |
|
57 continue; |
|
58 } |
|
59 if (argument == "--verbose") { |
|
60 m_verbose = true; |
|
61 continue; |
|
62 } |
|
63 |
|
64 // Skip any other arguments that begin with '--'. |
|
65 if (argument.length() >= 2 && argument[0] == '-' && argument[1] == '-') |
|
66 continue; |
|
67 |
|
68 m_paths.push_back(argument); |
|
69 } |
|
70 |
|
71 m_usingServerMode = (m_paths.size() == 1 && m_paths[0] == "-"); |
|
72 if (m_usingServerMode) |
|
73 m_printSeparators = true; |
|
74 else |
|
75 m_printSeparators = m_paths.size() > 1; |
|
76 |
|
77 initializeInjectedBundlePath(); |
|
78 initializeTestPluginPath(); |
|
79 |
|
80 m_context.adopt(WKContextCreateWithInjectedBundlePath(injectedBundlePath())); |
|
81 |
|
82 WKContextInjectedBundleClient injectedBundlePathClient = { |
|
83 0, |
|
84 this, |
|
85 _didRecieveMessageFromInjectedBundle |
|
86 }; |
|
87 WKContextSetInjectedBundleClient(m_context.get(), &injectedBundlePathClient); |
|
88 |
|
89 _WKContextSetAdditionalPluginPath(m_context.get(), testPluginPath()); |
|
90 |
|
91 m_pageNamespace.adopt(WKPageNamespaceCreate(m_context.get())); |
|
92 m_mainWebView = new PlatformWebView(m_pageNamespace.get()); |
|
93 } |
|
94 |
|
95 void TestController::runTest(const char* test) |
|
96 { |
|
97 m_currentInvocation.set(new TestInvocation(test)); |
|
98 m_currentInvocation->invoke(); |
|
99 m_currentInvocation.clear(); |
|
100 } |
|
101 |
|
102 void TestController::runTestingServerLoop() |
|
103 { |
|
104 char filenameBuffer[2048]; |
|
105 while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { |
|
106 char *newLineCharacter = strchr(filenameBuffer, '\n'); |
|
107 if (newLineCharacter) |
|
108 *newLineCharacter = '\0'; |
|
109 |
|
110 if (strlen(filenameBuffer) == 0) |
|
111 continue; |
|
112 |
|
113 runTest(filenameBuffer); |
|
114 } |
|
115 } |
|
116 |
|
117 bool TestController::run() |
|
118 { |
|
119 if (m_usingServerMode) |
|
120 runTestingServerLoop(); |
|
121 else { |
|
122 for (size_t i = 0; i < m_paths.size(); ++i) |
|
123 runTest(m_paths[i].c_str()); |
|
124 } |
|
125 |
|
126 return true; |
|
127 } |
|
128 |
|
129 void TestController::_didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo) |
|
130 { |
|
131 static_cast<TestController*>(const_cast<void*>(clientInfo))->didRecieveMessageFromInjectedBundle(message); |
|
132 } |
|
133 |
|
134 void TestController::didRecieveMessageFromInjectedBundle(WKStringRef message) |
|
135 { |
|
136 m_currentInvocation->didRecieveMessageFromInjectedBundle(message); |
|
137 } |
|
138 |
|
139 } // namespace WTR |