OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "TestCommon.h" | 32 #include "MockColorChooser.h" |
33 | 33 |
| 34 #include "WebTestDelegate.h" |
| 35 #include "WebTestProxy.h" |
| 36 |
| 37 using namespace WebKit; |
34 using namespace std; | 38 using namespace std; |
35 | 39 |
36 namespace WebTestRunner { | 40 namespace WebTestRunner { |
37 | 41 |
38 namespace { | 42 namespace { |
| 43 class HostMethodTask : public WebMethodTask<MockColorChooser> { |
| 44 public: |
| 45 typedef void (MockColorChooser::*CallbackMethodType)(); |
| 46 HostMethodTask(MockColorChooser* object, CallbackMethodType callback) |
| 47 : WebMethodTask<MockColorChooser>(object) |
| 48 , m_callback(callback) |
| 49 { } |
39 | 50 |
40 const char layoutTestsPattern[] = "/LayoutTests/"; | 51 virtual void runIfValid() { (m_object->*m_callback)(); } |
41 const string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1; | |
42 const char fileUrlPattern[] = "file:/"; | |
43 const char fileTestPrefix[] = "(file test):"; | |
44 const char dataUrlPattern[] = "data:"; | |
45 const string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1; | |
46 | 52 |
| 53 private: |
| 54 CallbackMethodType m_callback; |
| 55 }; |
47 } | 56 } |
48 | 57 |
49 string normalizeLayoutTestURL(const string& url) | 58 MockColorChooser::MockColorChooser(WebKit::WebColorChooserClient* client, WebTes
tDelegate* delegate, WebTestProxyBase* proxy) |
| 59 : m_client(client) |
| 60 , m_delegate(delegate) |
| 61 , m_proxy(proxy) |
50 { | 62 { |
51 string result = url; | 63 m_proxy->didOpenChooser(); |
52 size_t pos; | 64 } |
53 if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != st
ring::npos)) { | 65 |
54 // adjust file URLs to match upstream results. | 66 MockColorChooser::~MockColorChooser() |
55 result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix); | 67 { |
56 } else if (!url.find(dataUrlPattern)) { | 68 m_proxy->didCloseChooser(); |
57 // URL-escape data URLs to match results upstream. | 69 } |
58 string path = url.substr(dataUrlPatternSize); | 70 |
59 result.replace(dataUrlPatternSize, url.length(), path); | 71 void MockColorChooser::setSelectedColor(const WebKit::WebColor) |
60 } | 72 { |
61 return result; | 73 } |
| 74 |
| 75 void MockColorChooser::endChooser() |
| 76 { |
| 77 m_delegate->postDelayedTask(new HostMethodTask(this, &MockColorChooser::invo
keDidEndChooser), 0); |
| 78 } |
| 79 |
| 80 void MockColorChooser::invokeDidEndChooser() |
| 81 { |
| 82 m_client->didEndChooser(); |
62 } | 83 } |
63 | 84 |
64 } | 85 } |
OLD | NEW |