| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_TEST_RENDER_VIEW_TEST_H_ | |
| 6 #define CHROME_TEST_RENDER_VIEW_TEST_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/message_loop.h" | |
| 14 #include "chrome/renderer/autofill/autofill_agent.h" | |
| 15 #include "chrome/renderer/mock_keyboard.h" | |
| 16 #include "chrome/renderer/mock_render_thread.h" | |
| 17 #include "content/common/main_function_params.h" | |
| 18 #include "content/common/native_web_keyboard_event.h" | |
| 19 #include "content/common/sandbox_init_wrapper.h" | |
| 20 #include "content/renderer/render_view.h" | |
| 21 #include "content/renderer/renderer_webkitclient_impl.h" | |
| 22 #include "chrome/renderer/chrome_content_renderer_client.h" | |
| 23 #include "testing/gtest/include/gtest/gtest.h" | |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 25 | |
| 26 namespace autofill { | |
| 27 class AutofillAgent; | |
| 28 class PasswordAutofillManager; | |
| 29 } | |
| 30 | |
| 31 class ExtensionDispatcher; | |
| 32 class MockRenderProcess; | |
| 33 class RendererMainPlatformDelegate; | |
| 34 | |
| 35 class RenderViewTest : public testing::Test { | |
| 36 public: | |
| 37 // A special WebKitClientImpl class for getting rid off the dependency to the | |
| 38 // sandbox, which is not available in RenderViewTest. | |
| 39 class RendererWebKitClientImplNoSandbox : public RendererWebKitClientImpl { | |
| 40 public: | |
| 41 virtual WebKit::WebSandboxSupport* sandboxSupport() { | |
| 42 return NULL; | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 RenderViewTest(); | |
| 47 virtual ~RenderViewTest(); | |
| 48 | |
| 49 protected: | |
| 50 // Spins the message loop to process all messages that are currently pending. | |
| 51 void ProcessPendingMessages(); | |
| 52 | |
| 53 // Returns a pointer to the main frame. | |
| 54 WebKit::WebFrame* GetMainFrame(); | |
| 55 | |
| 56 // Executes the given JavaScript in the context of the main frame. The input | |
| 57 // is a NULL-terminated UTF-8 string. | |
| 58 void ExecuteJavaScript(const char* js); | |
| 59 | |
| 60 // Executes the given JavaScript and sets the int value it evaluates to in | |
| 61 // |result|. | |
| 62 // Returns true if the JavaScript was evaluated correctly to an int value, | |
| 63 // false otherwise. | |
| 64 bool ExecuteJavaScriptAndReturnIntValue(const string16& script, int* result); | |
| 65 | |
| 66 // Loads the given HTML into the main frame as a data: URL. | |
| 67 void LoadHTML(const char* html); | |
| 68 | |
| 69 // Sends IPC messages that emulates a key-press event. | |
| 70 int SendKeyEvent(MockKeyboard::Layout layout, | |
| 71 int key_code, | |
| 72 MockKeyboard::Modifiers key_modifiers, | |
| 73 std::wstring* output); | |
| 74 | |
| 75 // Sends one native key event over IPC. | |
| 76 void SendNativeKeyEvent(const NativeWebKeyboardEvent& key_event); | |
| 77 | |
| 78 // Returns the bounds (coordinates and size) of the element with id | |
| 79 // |element_id|. Returns an empty rect if such an element was not found. | |
| 80 gfx::Rect GetElementBounds(const std::string& element_id); | |
| 81 | |
| 82 // Sends a left mouse click in the middle of the element with id |element_id|. | |
| 83 // Returns true if the event was sent, false otherwise (typically because | |
| 84 // the element was not found). | |
| 85 bool SimulateElementClick(const std::string& element_id); | |
| 86 | |
| 87 // testing::Test | |
| 88 virtual void SetUp(); | |
| 89 | |
| 90 virtual void TearDown(); | |
| 91 | |
| 92 MessageLoop msg_loop_; | |
| 93 chrome::ChromeContentRendererClient chrome_content_renderer_client_; | |
| 94 ExtensionDispatcher* extension_dispatcher_; | |
| 95 MockRenderThread render_thread_; | |
| 96 scoped_ptr<MockRenderProcess> mock_process_; | |
| 97 scoped_refptr<RenderView> view_; | |
| 98 RendererWebKitClientImplNoSandbox webkitclient_; | |
| 99 scoped_ptr<MockKeyboard> mock_keyboard_; | |
| 100 | |
| 101 // Used to setup the process so renderers can run. | |
| 102 scoped_ptr<RendererMainPlatformDelegate> platform_; | |
| 103 scoped_ptr<MainFunctionParams> params_; | |
| 104 scoped_ptr<CommandLine> command_line_; | |
| 105 scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_; | |
| 106 | |
| 107 autofill::PasswordAutofillManager* password_autofill_; | |
| 108 autofill::AutofillAgent* autofill_agent_; | |
| 109 }; | |
| 110 | |
| 111 #endif // CHROME_TEST_RENDER_VIEW_TEST_H_ | |
| OLD | NEW |