~ubuntuone-control-tower/software-center/trunk

« back to all changes in this revision

Viewing changes to tests/gtk3/test_webkit.py

  • Committer: CI Train Bot
  • Author(s): Iain Lane
  • Date: 2016-02-17 13:47:35 UTC
  • mfrom: (3343.1.1 software-center)
  • Revision ID: ci-train-bot@canonical.com-20160217134735-8ed8171e5ypkuecx
Port to WebKit 2 Fixes: #1469221
Approved by: Iain Lane

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from gi.repository import (
4
4
    GLib,
5
5
    Soup,
6
 
    WebKit,
 
6
    WebKit2,
7
7
    )
8
8
 
9
9
from mock import patch
19
19
 
20
20
class TestWebkit(unittest.TestCase):
21
21
 
22
 
    def test_have_cookie_jar(self):
23
 
        # ensure we have a cookie jar available
24
 
        session = WebKit.get_default_session()
25
 
        cookie_jars = [feature 
26
 
                for feature in  session.get_features(Soup.SessionFeature)
27
 
                if isinstance(feature, Soup.CookieJar)]
28
 
        self.assertEqual(len(cookie_jars), 1)
29
 
    
30
22
    def test_user_agent_string(self):
31
23
        webview = SoftwareCenterWebView()
32
24
        settings = webview.get_settings()
33
 
        self.assertTrue(
34
 
            WEBKIT_USER_AGENT_SUFFIX in settings.get_property("user-agent"))
 
25
        self.assertTrue(WEBKIT_USER_AGENT_SUFFIX in settings.get_user_agent())
35
26
 
36
27
    @patch("softwarecenter.ui.gtk3.widgets.webkit.get_oem_channel_descriptor")
37
28
    def test_user_agent_oem_channel_descriptor(self, mock_oem_channel):
39
30
        mock_oem_channel.return_value = canary
40
31
        webview = SoftwareCenterWebView()
41
32
        settings = webview.get_settings()
42
 
        self.assertTrue(
43
 
            canary in settings.get_property("user-agent"))
44
 
        
 
33
        self.assertTrue(canary in settings.get_user_agent())
 
34
 
45
35
    def test_auto_fill_in_email(self):
46
36
        def _load_status_changed(view, status):
47
 
            if view.get_property("load-status") == WebKit.LoadStatus.FINISHED:
 
37
            if status == WebKit2.LoadEvent.FINISHED:
48
38
                loop.quit()
49
 
        loop =  GLib.MainLoop(GLib.main_context_default())       
 
39
        loop =  GLib.MainLoop(GLib.main_context_default())
50
40
        webview = SoftwareCenterWebView()
51
41
        email = "foo@bar"
52
42
        webview.set_auto_insert_email(email)
53
 
        with patch.object(webview, "execute_script") as mock_execute_js:
54
 
            webview.connect("notify::load-status", _load_status_changed)
 
43
        with patch.object(webview, "run_javascript") as mock_execute_js:
 
44
            webview.connect("load-changed", _load_status_changed)
55
45
            webview.load_uri("https://login.ubuntu.com")
56
46
            loop.run()
57
47
            mock_execute_js.assert_called()