TEST(WebKit2, ForceRepaint)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.base.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;

    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple-accelerated-compositing", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&test1Done);
    Util::run(&test2Done);
}
Example #2
0
QString GwtCallback::getSaveFileName(const QString& caption,
                                     const QString& dir,
                                     const QString& defaultExtension,
                                     bool forceDefaultExtension)
{
   QString resolvedDir = resolveAliasedPath(dir);

   while (true)
   {
      QString result = QFileDialog::getSaveFileName(pOwnerWindow_, caption, resolvedDir);
      webView()->page()->mainFrame()->setFocus();
      if (result.isEmpty())
         return result;

      if (!defaultExtension.isEmpty())
      {
         FilePath fp(result.toUtf8().constData());
         if (fp.extension().empty() ||
            (forceDefaultExtension &&
            (fp.extension() != defaultExtension.toStdString())))
         {
            result += defaultExtension;
            FilePath newExtPath(result.toUtf8().constData());
            if (newExtPath.exists())
            {
               std::string message = "\"" + newExtPath.filename() + "\" already "
                                     "exists. Do you want to overwrite it?";
               if (QMessageBox::Cancel == QMessageBox::warning(pOwnerWindow_,
                                        QString::fromUtf8("Save File"),
                                        QString::fromUtf8(message.c_str()),
                                        QMessageBox::Ok | QMessageBox::Cancel,
                                        QMessageBox::Ok))
               {
                  resolvedDir = result;
                  continue;
               }
            }
         }
      }

      return createAliasedPath(result);
   }
}
Example #3
0
WebTab::WebTab(MainWindow* parent) : QWidget(parent), TabbedWidget(this, parent)
#ifdef BUILD_AUDIO_TUTORIAL
	, m_audioTutorial(0)
#endif
{
	setupUi(this);
	
	connect(ui_webView, SIGNAL(titleChanged(const QString&)), this, SLOT(updateTitle(const QString&)));
	connect(ui_webView, SIGNAL(urlChanged(const QUrl&)), this, SLOT(updateUrl(const QUrl&)));
	
	ui_webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
	connect(webView(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(linkClicked(const QUrl&)));
	
	ui_frameFind->hide();
	
	m_fragmentMacro["KISS_CWD"] = new CurrentDirectoryMacro();
	
	ui_webView->history()->clear();
}
Example #4
0
TEST(WebKit2, FailedLoad)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
    PlatformWebView webView(pageNamespace.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.version = 0;
    loaderClient.clientInfo = 0;
    loaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::URLForNonExistentResource());
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&testDone);
}
Example #5
0
void WinLauncher::setUserAgent(UINT menuID)
{
    if (!webView())
        return;

    _bstr_t customUserAgent;
    switch (menuID) {
    case IDM_UA_DEFAULT:
        // Set to null user agent
        break;
    case IDM_UA_SAFARI_8_0:
        customUserAgent = L"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25";
        break;
    case IDM_UA_SAFARI_IOS_8_IPHONE:
        customUserAgent = L"Mozilla/5.0 (iPhone; CPU OS 8_1 like Mac OS X) AppleWebKit/601.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B403 Safari/600.1.4";
        break;
    case IDM_UA_SAFARI_IOS_8_IPAD:
        customUserAgent = L"Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B403 Safari/600.1.4";
        break;
    case IDM_UA_IE_11:
        customUserAgent = L"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko";
        break;
    case IDM_UA_CHROME_MAC:
        customUserAgent = L"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31";
        break;
    case IDM_UA_CHROME_WIN:
        customUserAgent = L"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
        break;
    case IDM_UA_FIREFOX_MAC:
        customUserAgent = L"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20100101 Firefox/20.0";
        break;
    case IDM_UA_FIREFOX_WIN:
        customUserAgent = L"Mozilla/5.0 (Windows NT 6.2; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";
        break;
    case IDM_UA_OTHER:
    default:
        ASSERT(0); // We should never hit this case
        return;
    }

    setUserAgent(customUserAgent);
}
Example #6
0
TEST(WebKit2, FrameMIMETypePNG)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.version = 0;
    loaderClient.clientInfo = 0;
    loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
    loaderClient.didCommitLoadForFrame = didCommitLoadForFrame;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("icon", "png"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&testDone);
}
SecondaryWindow::SecondaryWindow(bool showToolbar, QString name, QUrl baseUrl,
                                 QWidget* pParent, WebPage* pOpener,
                                 bool allowExternalNavigate) :
    BrowserWindow(showToolbar, true, name, baseUrl, pParent, pOpener,
                  allowExternalNavigate)
{
   setAttribute(Qt::WA_QuitOnClose, true);
   setAttribute(Qt::WA_DeleteOnClose, true);

#ifdef Q_OS_MAC
   setIconSize(QSize(26, 22));
#else
   setIconSize(QSize(26, 20));
#endif

   back_ = pToolbar_->addAction(icon("back"), QString::fromUtf8("Back"));
   back_->setToolTip(QString::fromUtf8("Back"));
   connect(back_, SIGNAL(triggered()),
           webView(), SLOT(back()));

   forward_ = pToolbar_->addAction(icon("forward"), QString::fromUtf8("Forward"));
   forward_->setToolTip(QString::fromUtf8("Forward"));
   connect(forward_, SIGNAL(triggered()),
           webView(), SLOT(forward()));

   reload_ = pToolbar_->addAction(icon("reload"), QString::fromUtf8("Reload"));
   reload_->setToolTip(QString::fromUtf8("Reload"));
   connect(reload_, SIGNAL(triggered()),
           webView(), SLOT(reload()));

   connect(webView(), SIGNAL(loadStarted()),
           this, SLOT(manageCommandState()));
   connect(webView(), SIGNAL(urlChanged(QUrl)),
           this, SLOT(manageCommandState()));

   manageCommandState();

   // Size it (use computed size if it seems sane; otherwise let Qt set it)
   QSize size = QSize(850, 1100).boundedTo(
         QApplication::desktop()->availableGeometry().size());
   if (size.width() > 500 && size.height() > 500)
   {
      size.setHeight(size.height()-75);
      resize(size);
   }

   connect(webView(), SIGNAL(onCloseWindowShortcut()),
           this, SLOT(onCloseWindowShortcut()));
}
TEST(WebKit2, GetInjectedBundleInitializationUserDataCallback)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBundle());

    WKContextInjectedBundleClientV1 injectedBundleClient;
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));

    injectedBundleClient.base.version = 1;
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
    injectedBundleClient.getInjectedBundleInitializationUserData = getInjectedBundleInitializationUserData;

    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);

    PlatformWebView webView(context.get());

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&done);
}
TEST(WebKit2, InjectedBundleMakeAllShadowRootOpenTest)
{
    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("InjectedBundleMakeAllShadowRootOpenTestPageGroup")));

    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleMakeAllShadowRootOpenTest", pageGroup.get()));
    PlatformWebView webView(context.get(), pageGroup.get());

    WKPageUIClientV0 uiClient;
    memset(&uiClient, 0, sizeof(uiClient));

    uiClient.base.version = 0;
    uiClient.runJavaScriptAlert = runJavaScriptAlert;

    WKPageSetPageUIClient(webView.page(), &uiClient.base);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("closed-shadow-tree-test", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&done);
}
TEST(WebKit2, CloseFromWithinCreatePage)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());

    PlatformWebView webView(context.get());

    WKPageUIClientV5 uiClient;
    memset(&uiClient, 0, sizeof(uiClient));

    uiClient.base.version = 5;
    uiClient.createNewPage = createNewPage;
    uiClient.runJavaScriptAlert = runJavaScriptAlert;
    WKPageSetPageUIClient(webView.page(), &uiClient.base);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("close-from-within-create-page", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&testDone);

    openedWebView = nullptr;
}
TEST(WebKit2, CloseThenTerminate)
{
    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0 , sizeof(loaderClient));

    loaderClient.base.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    
    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&loaded);

    WKPageClose(webView.page());
    WKPageTerminate(webView.page());
}
TEST(WebKit2, LoadAlternateHTMLStringWithNonDirectoryURL)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    
    loaderClient.base.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);

    WKRetainPtr<WKURLRef> fileURL(AdoptWK, Util::createURLForResource("simple", "html"));
    WKRetainPtr<WKStringRef> alternateHTMLString(AdoptWK, WKStringCreateWithUTF8CString("<html><body><img src='icon.png'></body></html>"));
    
    // Call WKPageLoadAlternateHTMLString() with fileURL which does not point to a directory
    WKPageLoadAlternateHTMLString(webView.page(), alternateHTMLString.get(), fileURL.get(), fileURL.get());
    
    // If we can finish loading the html without resulting in an invalid message being sent from the WebProcess, this test passes.
    Util::run(&didFinishLoad);
}
TEST_F(WebPageNewSerializeTest, TestMHTMLEncodingWithMorphingDataURL)
{
    // Load a page with some data urls.
    WebURL topFrameURL = toKURL(m_baseURL);
    registerMockedURLLoad(topFrameURL, WebString::fromUTF8("page_with_morphing_data.html"), WebString::fromUTF8("pageserializer/"), htmlMimeType());
    loadURLInTopFrame(topFrameURL);

    WebCString mhtmlData = WebPageSerializer::serializeToMHTML(webView());
    ASSERT_FALSE(mhtmlData.isEmpty());

    // Read the MHTML data line and check that the string data:image is found
    // exactly two times.
    size_t nbDataURLs = 0;
    LineReader lineReader(std::string(mhtmlData.data()));
    std::string line;
    while (lineReader.getNextLine(&line)) {
        if (line.find("data:text") != std::string::npos)
            nbDataURLs++;
    }
    EXPECT_EQ(2u, nbDataURLs);
}
Example #14
0
TEST(WebKit2, FrameHandle)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    loaderClient.base.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);

    WKPageLoadURL(webView.page(), adoptWK(WKURLCreateWithUTF8CString("about:blank")).get());
    Util::run(&done);

    auto frame = WKPageGetMainFrame(webView.page());
    auto frameInfo = adoptWK(WKFrameCreateFrameInfo(frame));
    auto handleFromInfo = WKFrameInfoGetFrameHandleRef(frameInfo.get());
    auto handleFromFrame = adoptWK(WKFrameCreateFrameHandle(frame));

    EXPECT_EQ(WKFrameHandleGetFrameID(handleFromInfo), WKFrameHandleGetFrameID(handleFromFrame.get()));
}
TEST_F(WebPageSerializerTest, EncodingAndNormalization)
{
    WebURL topFrameURL = toKURL("http://www.test.com");
    registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("encoding_normalization.html"));

    loadURLInTopFrame(topFrameURL);

    SimpleWebPageSerializerClient serializerClient;
    WebVector<WebURL> links(&topFrameURL, 1);
    WebVector<WebString> localPaths(&"local", 1);
    WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &serializerClient, links, localPaths, "");

    const char* expectedHTML =
        "<!DOCTYPE html>\n"
        "<!-- saved from url=(0020)http://www.test.com/ -->\n"
        "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-KR\"><meta charset=\"euc-kr\">\n"
        "<title>Ensure NFC normalization is not performed by page serializer</title>\n"
        "</head><body>\n"
        "\xe4\xc5\xd1\xe2\n"
        "\n</body></html>";
    EXPECT_EQ(expectedHTML, serializerClient.toString());
}
TEST(WebKit2, ShouldGoToBackForwardListItem)
{
    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ShouldGoToBackForwardListItemTest"));
    // Enable the page cache so we can test the WKBundleBackForwardListItemIsInPageCache API
    WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser);

    PlatformWebView webView(context.get());
    setPageLoaderClient(webView.page());

    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get());
    Util::run(&finished);
    
    finished = false;
    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get());
    Util::run(&finished);

    finished = false;
    WKPageGoBack(webView.page());
    Util::run(&finished);
    
    EXPECT_EQ(receivedProperBackForwardCallbacks, true);
}
TEST_F(WebPageSerializerTest, URLAttributeValues)
{
    WebURL topFrameURL = toKURL("http://www.test.com");
    registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("url_attribute_values.html"));
    registerMockedImageURL("javascript:\"");

    loadURLInTopFrame(topFrameURL);

    SimpleWebPageSerializerClient serializerClient;
    WebVector<WebURL> links(&topFrameURL, 1);
    WebVector<WebString> localPaths(&"local", 1);
    WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &serializerClient, links, localPaths, "");

    const char* expectedHTML =
        "\n<!-- saved from url=(0020)http://www.test.com/ -->\n"
        "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta charset=\"utf8\">\n"
        "</head><body><img src=\"javascript:&quot;\">\n"
        "<a href=\"http://www.test.com/local#&quot;\">local</a>\n"
        "<a href=\"http://www.example.com/#&quot;&gt;&lt;script&gt;alert(0)&lt;/script&gt;\">external</a>\n"
        "</body></html>";
    EXPECT_EQ(expectedHTML, serializerClient.toString());
}
Example #18
0
QString GwtCallback::getExistingDirectory(const QString& caption,
                                         const QString& dir)
{
   QString resolvedDir = resolveAliasedPath(dir);

   QString result;
#ifdef _WIN32
   if (dir.isNull())
   {
      // Bug
      wchar_t szDir[MAX_PATH];
      BROWSEINFOW bi;
      bi.hwndOwner = pOwnerWindow_->winId();
      bi.pidlRoot = NULL;
      bi.pszDisplayName = szDir;
      bi.lpszTitle = L"Select a folder:";
      bi.ulFlags = BIF_RETURNONLYFSDIRS;
      bi.lpfn = NULL;
      bi.lpfn = 0;
      bi.iImage = -1;
      LPITEMIDLIST pidl = SHBrowseForFolderW(&bi);
      if (!pidl || !SHGetPathFromIDListW(pidl, szDir))
         result = QString();
      else
         result = QString::fromWCharArray(szDir);
   }
   else
   {
      result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir);
   }
#else
   result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir);
#endif

   webView()->page()->mainFrame()->setFocus();
   return createAliasedPath(result);
}
TEST(WebKit2, MouseMoveAfterCrash)
#endif
{
    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest"));

    PlatformWebView webView(context.get());
    setPageLoaderClient(webView.page());

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("mouse-move-listener", "html"));
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&didFinishLoad);

    didFinishLoad = false;

    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("Pause").get(), 0);

    webView.simulateSpacebarKeyPress();

    // Move the mouse once we are hung.
    webView.simulateMouseMove(10, 10);
    webView.simulateMouseMove(20, 20);

    // After moving the mouse (while the web process was hung on the Pause message), kill the web process. It is restarted by reloading the page.
    WKPageTerminate(webView.page());
    WKPageReload(webView.page());

    // Wait until we load the page a second time.
    Util::run(&didFinishLoad);

    EXPECT_JS_FALSE(webView.page(), "didMoveMouse()");

    // Once the page has reloaded, try moving the mouse to verify that we get mouse move events.
    webView.simulateMouseMove(10, 10);
    webView.simulateMouseMove(20, 20);

    EXPECT_JS_TRUE(webView.page(), "didMoveMouse()");
}
TEST(WebKit2, HideFindIndicator)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());
    initialize(webView);

    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("find", "html"));
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&didFinishLoad);
    didFinishLoad = false;

    WKPageFindString(webView.page(), Util::toWK("Hello").get(), kWKFindOptionsShowFindIndicator, 100);
    Util::run(&findIndicatorCallbackWasCalled);
    findIndicatorCallbackWasCalled = false;

    TEST_ASSERT(bitmap);
    ::DeleteObject(bitmap);
    bitmap = 0;

    WKPageHideFindUI(webView.page());
    Util::run(&findIndicatorCallbackWasCalled);

    TEST_ASSERT(!bitmap);
}
TEST(WebKit2, AltKeyGeneratesWMSysCommand)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageUIClient uiClient;
    memset(&uiClient, 0, sizeof(uiClient));

    uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback;
    WKPageSetPageUIClient(webView.page(), &uiClient);

    WMSysCommandObserver observer;
    webView.setParentWindowMessageObserver(&observer);

    webView.simulateAltKeyPress();

    Util::run(&didNotHandleWMSysKeyUp);

    webView.setParentWindowMessageObserver(0);

    // The WM_SYSKEYUP message should have generated a WM_SYSCOMMAND message that was sent to the
    // WKView's parent window.
    EXPECT_TRUE(observer.windowDidReceiveWMSysCommand());
}
TEST(WebKit2, ReloadPageAfterCrash)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.base.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoad;
    loaderClient.processDidCrash = didCrash;

    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);

    WKRetainPtr<WKURLRef> url = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
    // Load a blank page and next kills WebProcess.
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&loadBeforeCrash);
    WKPageTerminate(webView.page());

    // Let's try load a page and see what happens.
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&loadAfterCrash);
}
TEST(WebKit2, PageLoadDidChangeLocationWithinPageForFrame)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    loaderClient.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("file-with-anchor", "html"));
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&didFinishLoad);

    WKRetainPtr<WKURLRef> initialURL = adoptWK(WKFrameCopyURL(WKPageGetMainFrame(webView.page())));

    WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("clickLink()").get(), 0, nullJavaScriptCallback);
    Util::run(&didChangeLocationWithinPage);

    WKRetainPtr<WKURLRef> urlAfterAnchorClick = adoptWK(WKFrameCopyURL(WKPageGetMainFrame(webView.page())));

    TEST_ASSERT(!WKURLIsEqual(initialURL.get(), urlAfterAnchorClick.get()));
}
SecondaryWindow::SecondaryWindow(QUrl baseUrl, QWidget* pParent) :
    BrowserWindow(true, true, baseUrl, pParent)
{
   setAttribute(Qt::WA_QuitOnClose, false);
   setAttribute(Qt::WA_DeleteOnClose, true);

#ifdef Q_WS_MACX
   setIconSize(QSize(26, 22));
#else
   setIconSize(QSize(26, 20));
#endif

   back_ = pToolbar_->addAction(icon("back"), QString::fromUtf8("Back"));
   back_->setToolTip(QString::fromUtf8("Back"));
   connect(back_, SIGNAL(triggered()),
           webView(), SLOT(back()));

   forward_ = pToolbar_->addAction(icon("forward"), QString::fromUtf8("Forward"));
   forward_->setToolTip(QString::fromUtf8("Forward"));
   connect(forward_, SIGNAL(triggered()),
           webView(), SLOT(forward()));

   reload_ = pToolbar_->addAction(icon("reload"), QString::fromUtf8("Reload"));
   reload_->setToolTip(QString::fromUtf8("Reload"));
   connect(reload_, SIGNAL(triggered()),
           webView(), SLOT(reload()));

   print_ = pToolbar_->addAction(icon("print"), QString::fromUtf8("Print"));
   print_->setToolTip(QString::fromUtf8("Print"));
   connect(print_, SIGNAL(triggered()),
           this, SLOT(print()));

   history_ = webView()->history();

   connect(webView(), SIGNAL(loadStarted()),
           this, SLOT(manageCommandState()));
   connect(webView(), SIGNAL(urlChanged(QUrl)),
           this, SLOT(manageCommandState()));

   manageCommandState();
}
Example #25
0
WBWebView *WBTabWidget::currentWebView() const
{
    return webView(currentIndex());
}
TEST(WebKit2, WKViewUserViewportToContents)
{
    // This test creates a WKView and uses the WKViewUserViewportToContents
    // function to convert viewport coordinates to contents (page) coordinates.
    // It scrolls and scales around the contents and check if the coordinates
    // conversion math is right.

    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKViewRef> webView(AdoptWK, WKViewCreate(context.get(), 0));

    WKViewInitialize(webView.get());
    WKPageSetUseFixedLayout(WKViewGetPage(webView.get()), false);

    WKPoint out;

    // At scale 1.0 the viewport and contents coordinates should match.

    WKViewSetContentScaleFactor(webView.get(), 1.0);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 10);
    EXPECT_EQ(out.y, 10);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 30);
    EXPECT_EQ(out.y, 30);

    // At scale 2.0 the viewport distance values will be half
    // the ones seem in the contents.

    WKViewSetContentScaleFactor(webView.get(), 2.0);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 5);
    EXPECT_EQ(out.y, 5);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 25);
    EXPECT_EQ(out.y, 25);

    // At scale 0.5 the viewport distance values will be twice
    // the ones seem in the contents.

    WKViewSetContentScaleFactor(webView.get(), 0.5);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 40);
    EXPECT_EQ(out.y, 40);

    // Let's add translation to the viewport.

    const int delta = 10;
    WKViewSetUserViewportTranslation(webView.get(), delta, delta);

    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0 - delta / 0.5);
    EXPECT_EQ(out.y, 0 - delta / 0.5);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 20 - delta / 0.5);
    EXPECT_EQ(out.y, 20 - delta / 0.5);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20 - delta / 0.5);
    EXPECT_EQ(out.y, 20 - delta / 0.5);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 40 - delta / 0.5);
    EXPECT_EQ(out.y, 40 - delta / 0.5);
}
 void SetUp() override
 {
     m_helper.initialize(false, &m_webFrameClient, &m_webViewClient);
     webView()->setUseExternalPopupMenus(true);
 }
 void loadFrame(const std::string& fileName)
 {
     FrameTestHelpers::loadFrame(mainFrame(), m_baseURL + fileName);
     webView()->resize(WebSize(800, 600));
     webView()->updateAllLifecyclePhases();
 }
void SecondaryWindow::print()
{
   printRequested(webView()->page()->mainFrame());
}
Example #30
0
void WebViewHelper::resize(WebSize size) {
  m_testWebViewClient->clearAnimationScheduled();
  webView()->resize(size);
  EXPECT_FALSE(m_testWebViewClient->animationScheduled());
  m_testWebViewClient->clearAnimationScheduled();
}