int main(int argc, char* argv[]) { Options options; if (!options.parse(argc, argv)) return 1; printf("MiniBrowser: Use Alt + Left and Alt + Right to navigate back and forward. Use F5 to reload.\n"); std::string url = options.url; if (url.empty()) url = "http://www.google.com"; else if (url.find("http") != 0 && url.find("file://") != 0) { std::ifstream localFile(url.c_str()); url.insert(0, localFile ? "file://" : "http://"); } GMainLoop* mainLoop = g_main_loop_new(0, false); MiniBrowser browser(mainLoop, options.desktopModeEnabled ? MiniBrowser::DesktopMode : MiniBrowser::MobileMode, options.width, options.height, options.viewportHorizontalDisplacement, options.viewportVerticalDisplacement); if (options.forceTouchEmulationEnabled || !options.desktopModeEnabled) { printf("Touch Emulation Mode enabled. Hold Control key to build and emit a multi-touch event: each mouse button should be a different touch point. Release Control Key to clear all tracking pressed touches.\n"); browser.setTouchEmulationMode(true); } if (!options.userAgent.empty()) WKPageSetCustomUserAgent(browser.pageRef(), WKStringCreateWithUTF8CString(options.userAgent.c_str())); if (!options.desktopModeEnabled) printf("Use Control + mouse wheel to zoom in and out.\n"); WKPageLoadURL(browser.pageRef(), WKURLCreateWithUTF8CString(url.c_str())); g_main_loop_run(mainLoop); g_main_loop_unref(mainLoop); }
TEST(WebKit2, PreventEmptyUserAgent) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); WKPageSetCustomUserAgent(webView.page(), WKStringCreateWithUTF8CString("")); WKRetainPtr<WKStringRef> javaScriptString(AdoptWK, WKStringCreateWithUTF8CString("navigator.userAgent")); WKPageRunJavaScriptInMainFrame(webView.page(), javaScriptString.get(), reinterpret_cast<void*>(0x1234578), didRunJavaScript); Util::run(&testDone); }