| 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 |
| 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<MockColorChooser> { |
| 43 public: |
| 44 typedef void (MockColorChooser::*CallbackMethodType)(); |
| 45 HostMethodTask(MockColorChooser* object, CallbackMethodType callback) |
| 46 : WebMethodTask<MockColorChooser>(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 MockColorChooser::MockColorChooser(WebKit::WebColorChooserClient* client, WebTes
tDelegate* delegate) |
| 58 : m_client(client) |
| 59 , m_delegate(delegate) |
| 50 { | 60 { |
| 51 string result = url; | 61 m_delegate->didChooserOpen(); |
| 52 size_t pos; | 62 } |
| 53 if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != st
ring::npos)) { | 63 |
| 54 // adjust file URLs to match upstream results. | 64 MockColorChooser::~MockColorChooser() |
| 55 result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix); | 65 { |
| 56 } else if (!url.find(dataUrlPattern)) { | 66 m_delegate->didChooserClose(); |
| 57 // URL-escape data URLs to match results upstream. | 67 } |
| 58 string path = url.substr(dataUrlPatternSize); | 68 |
| 59 result.replace(dataUrlPatternSize, url.length(), path); | 69 void MockColorChooser::setSelectedColor(const WebKit::WebColor) |
| 60 } | 70 { |
| 61 return result; | 71 } |
| 72 |
| 73 void MockColorChooser::endChooser() |
| 74 { |
| 75 m_delegate->postDelayedTask(new HostMethodTask(this, &MockColorChooser::invo
keDidEndChooser), 0); |
| 76 } |
| 77 |
| 78 void MockColorChooser::invokeDidEndChooser() |
| 79 { |
| 80 m_client->didEndChooser(); |
| 62 } | 81 } |
| 63 | 82 |
| 64 } | 83 } |
| OLD | NEW |