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 "ColorChooser.h" |
33 | 33 |
| 34 #include "WebTestDelegate.h" |
| 35 |
| 36 using namespace WebKit; |
34 using namespace std; | 37 using namespace std; |
35 | 38 |
36 namespace WebTestRunner { | 39 namespace WebTestRunner { |
37 | 40 |
38 namespace { | 41 namespace { |
| 42 class HostMethodTask : public WebMethodTask<ColorChooser> { |
| 43 public: |
| 44 typedef void (ColorChooser::*CallbackMethodType)(); |
| 45 HostMethodTask(ColorChooser* object, CallbackMethodType callback) |
| 46 : WebMethodTask<ColorChooser>(object) |
| 47 , m_callback(callback) |
| 48 { } |
39 | 49 |
40 const char layoutTestsPattern[] = "/LayoutTests/"; | 50 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 | 51 |
| 52 private: |
| 53 CallbackMethodType m_callback; |
| 54 }; |
47 } | 55 } |
48 | 56 |
49 string normalizeLayoutTestURL(const string& url) | 57 ColorChooser::ColorChooser(WebKit::WebColorChooserClient* client, WebTestDelegat
e* delegate) |
| 58 : m_client(client) |
| 59 , m_delegate(delegate) |
50 { | 60 { |
51 string result = url; | 61 } |
52 size_t pos; | 62 |
53 if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != st
ring::npos)) { | 63 ColorChooser::~ColorChooser() |
54 // adjust file URLs to match upstream results. | 64 { |
55 result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix); | 65 } |
56 } else if (!url.find(dataUrlPattern)) { | 66 |
57 // URL-escape data URLs to match results upstream. | 67 void ColorChooser::setSelectedColor(const WebKit::WebColor) |
58 string path = url.substr(dataUrlPatternSize); | 68 { |
59 result.replace(dataUrlPatternSize, url.length(), path); | 69 } |
60 } | 70 |
61 return result; | 71 void ColorChooser::endChooser() |
| 72 { |
| 73 m_delegate->postDelayedTask(new HostMethodTask(this, &ColorChooser::invokeDi
dEndChooser), 0); |
| 74 } |
| 75 |
| 76 void ColorChooser::invokeDidEndChooser() |
| 77 { |
| 78 m_client->didEndChooser(); |
62 } | 79 } |
63 | 80 |
64 } | 81 } |
OLD | NEW |