| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 26 matching lines...) Expand all Loading... |
| 37 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 38 #include <string> | 38 #include <string> |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class WebLocalFrameImpl; | 42 class WebLocalFrameImpl; |
| 43 class WebSettings; | 43 class WebSettings; |
| 44 | 44 |
| 45 namespace FrameTestHelpers { | 45 namespace FrameTestHelpers { |
| 46 | 46 |
| 47 class TestWebFrameClient; | |
| 48 | |
| 49 // Loads a url into the specified WebFrame for testing purposes. Pumps any | |
| 50 // pending resource requests, as well as waiting for the threaded parser to | |
| 51 // finish, before returning. | |
| 52 void loadFrame(WebFrame*, const std::string& url); | 47 void loadFrame(WebFrame*, const std::string& url); |
| 53 // Same as above, but for WebFrame::loadHTMLString(). | |
| 54 void loadHTMLString(WebFrame*, const std::string& html, const WebURL& baseURL); | |
| 55 // Same as above, but for WebFrame::reload(). | |
| 56 void reloadFrame(WebFrame*); | |
| 57 void reloadFrameIgnoringCache(WebFrame*); | |
| 58 | |
| 59 // Pumps pending resource requests while waiting for a frame to load. Don't use | |
| 60 // this. Use one of the above helpers. | |
| 61 void pumpPendingRequestsDoNotUse(WebFrame*); | |
| 62 | |
| 63 void runPendingTasks(); | 48 void runPendingTasks(); |
| 64 | 49 |
| 65 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. | 50 // Convenience class for handling the lifetime of a WebView and its associated m
ainframe in tests. |
| 66 class WebViewHelper { | 51 class WebViewHelper { |
| 67 WTF_MAKE_NONCOPYABLE(WebViewHelper); | 52 WTF_MAKE_NONCOPYABLE(WebViewHelper); |
| 68 public: | 53 public: |
| 69 WebViewHelper(); | 54 WebViewHelper(); |
| 70 ~WebViewHelper(); | 55 ~WebViewHelper(); |
| 71 | 56 |
| 72 // Creates and initializes the WebView. Implicitly calls reset() first. IF a | 57 // Creates and initializes the WebView. Implicitly calls reset() first. IF a |
| 73 // WebFrameClient or a WebViewClient are passed in, they must outlive the | 58 // WebFrameClient or a WebViewClient are passed in, they must outlive the |
| 74 // WebViewHelper. | 59 // WebViewHelper. |
| 75 WebViewImpl* initialize(bool enableJavascript = false, TestWebFrameClient* =
0, WebViewClient* = 0, void (*updateSettingsFunc)(WebSettings*) = 0); | 60 WebViewImpl* initialize(bool enableJavascript = false, WebFrameClient* = 0,
WebViewClient* = 0, void (*updateSettingsFunc)(WebSettings*) = 0); |
| 76 | 61 |
| 77 // Same as initialize() but also performs the initial load of the url. | 62 // Same as initialize() but also performs the initial load of the url. |
| 78 WebViewImpl* initializeAndLoad(const std::string& url, bool enableJavascript
= false, TestWebFrameClient* = 0, WebViewClient* = 0, void (*updateSettingsFunc
)(WebSettings*) = 0); | 63 WebViewImpl* initializeAndLoad(const std::string& url, bool enableJavascript
= false, WebFrameClient* = 0, WebViewClient* = 0, void (*updateSettingsFunc)(We
bSettings*) = 0); |
| 79 | 64 |
| 80 void reset(); | 65 void reset(); |
| 81 | 66 |
| 82 WebView* webView() const { return m_webView; } | 67 WebView* webView() const { return m_webView; } |
| 83 WebViewImpl* webViewImpl() const { return m_webView; } | 68 WebViewImpl* webViewImpl() const { return m_webView; } |
| 84 | 69 |
| 85 private: | 70 private: |
| 86 WebViewImpl* m_webView; | 71 WebViewImpl* m_webView; |
| 87 }; | 72 }; |
| 88 | 73 |
| 89 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load | 74 // Minimal implementation of WebFrameClient needed for unit tests that load fram
es. Tests that load |
| 90 // frames and need further specialization of WebFrameClient behavior should subc
lass this. | 75 // frames and need further specialization of WebFrameClient behavior should subc
lass this. |
| 91 class TestWebFrameClient : public WebFrameClient { | 76 class TestWebFrameClient : public WebFrameClient { |
| 92 public: | 77 public: |
| 93 TestWebFrameClient(); | |
| 94 | |
| 95 virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& f
rameName) OVERRIDE; | 78 virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& f
rameName) OVERRIDE; |
| 96 virtual void frameDetached(WebFrame*) OVERRIDE; | 79 virtual void frameDetached(WebFrame*) OVERRIDE; |
| 97 virtual void didStartLoading(bool) OVERRIDE; | |
| 98 virtual void didStopLoading() OVERRIDE; | |
| 99 | |
| 100 bool isLoading() { return m_loadsInProgress > 0; } | |
| 101 | |
| 102 private: | |
| 103 int m_loadsInProgress; | |
| 104 }; | 80 }; |
| 105 | 81 |
| 106 class TestWebViewClient : public WebViewClient { | 82 class TestWebViewClient : public WebViewClient { |
| 107 public: | 83 public: |
| 108 virtual ~TestWebViewClient() { } | 84 virtual ~TestWebViewClient() { } |
| 109 virtual void initializeLayerTreeView() OVERRIDE; | 85 virtual void initializeLayerTreeView() OVERRIDE; |
| 110 virtual WebLayerTreeView* layerTreeView() OVERRIDE { return m_layerTreeView.
get(); } | 86 virtual WebLayerTreeView* layerTreeView() OVERRIDE { return m_layerTreeView.
get(); } |
| 111 | 87 |
| 112 private: | 88 private: |
| 113 OwnPtr<WebLayerTreeView> m_layerTreeView; | 89 OwnPtr<WebLayerTreeView> m_layerTreeView; |
| 114 }; | 90 }; |
| 115 | 91 |
| 116 } // namespace FrameTestHelpers | 92 } // namespace FrameTestHelpers |
| 117 } // namespace blink | 93 } // namespace blink |
| 118 | 94 |
| 119 #endif // FrameTestHelpers_h | 95 #endif // FrameTestHelpers_h |
| OLD | NEW |